I need to test Django application behavior for concurrent requests. I need to test is database data correct after that. As a cnclusion, I need to test and transactions mechanism. So let's use TransactionTestCase
for that.
I spawned requests to database using threading and got 'DatabaseError: no such table: app_modelname exception' in threads because of automatic switching to in-memory database type (for SQLite by Django when running test).
Of course, I can specify 'TEST_NAME'
for 'default'
key in settings.DATABASES
, and test will pass as expected. But this also used for all tests too, so tests running takes a much more time.
- I thought about custom database router, but it seems to be very
hackish way to do that since I need to patch / mock a lot of
attributes in models to define is this executed in
TransactionTestCase
or not. - There was also idea to use
override_settings
but unfortunately it does not work (see issue for details)
How I can specify (or create) not in-memory database (on hard drive) for just a few test cases (TransactionTestCase
) and left others to run with in-memory database?
Any thoughts, ideas or code samples will be appreciated. Thanks!