I've had a similar problem trying to get some locking unit tests
working. Unfortunately I don't have a neat solution: I gave up in the
end :(
The first problem was, as you guessed, that the database connection
(or more specifically the cursor), can't be shared between threads.
IIRC it is stored as a thread-local variable and won't be correctly
initialised for the new threads. I managed to get it initialised by
doing the following:
import django.db
django.db.close_connection()
cursor = connection.cursor()
...however, that initialised it to use the *real* database, not the
test one. Very confusing test failures it produced, too :) Anyway, I
tried a few different things to try and get it all working, but gave
up after a while. I intend to come back to it at some point so if you
manage to get this working I'd be very interested in the solution!
> Thanks,
> Brian
Cheers,
Duane.
--
"I never could learn to drink that blood and call it wine" - Bob Dylan
Right.
> Can the database connection (and hence transaction) be shared between
> the threads? Has anyone encountered this problem before? (And,
> ideally, came up with a really neat solution...)
Try to use TransactionTestCase instead of TestCase (and don't use
in-memory SQLite datebase).
--
Kirill Spitsin