I don't think so.
See "Tests requiring multiple databases" in docs/database.rst.
@pelme
I think for this we should provide a fixture that can be overwritten and wraps the Django TestCase class?
Django uses this _database_names method: https://github.com/django/django/blob/ab2f5f764a2f6db97e23cccd5c4f5abbb43d1caf/django/test/testcases.py#L869-L877
I have tried the following:
@pytest.fixture
def use_multidb_for_django_testcases(monkeypatch):
monkeypatch.setattr('django.test.TransactionTestCase.multi_db', True,
raising=False)
@pytest.fixture
def django_multidb(use_multidb_for_django_testcases, db):
return db
def test_foo(django_multidb, …):
With --reuse-db I am getting this error on teardown:
..…/Vcs/django/django/test/testcases.py:924: in _post_teardown
self._fixture_teardown()
..…/Vcs/django/django/test/testcases.py:1078: in _fixture_teardown
self._rollback_atomics(self.atomics)
..…/Vcs/django/django/test/testcases.py:1020: in _rollback_atomics
transaction.set_rollback(True, using=db_name)
..…/Vcs/django/django/db/transaction.py:103: in set_rollback
return get_connection(using).set_rollback(rollback)
..…/Vcs/django/django/db/backends/base/base.py:415: in set_rollback
"The rollback flag doesn't work outside of an 'atomic' block.")
E django.db.transaction.TransactionManagementError: The rollback flag doesn't work outside of an 'atomic' block.
With --create-db it results in:
project/app/tests/test_models.py::test_db_router ERRORDestroying test database for alias 'replica' ('test_project')...
Traceback (most recent call last):
File "…/Vcs/django/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
psycopg2.OperationalError: database "test_project" is being accessed by other users
DETAIL: There is 1 other session using the database.
I think once we have multi-db support, then this should follow naturally, so I'll close as a duplicate (there are many issues about mutli db).
Most helpful comment
I don't think so.
See "Tests requiring multiple databases" in
docs/database.rst.@pelme
I think for this we should provide a fixture that can be overwritten and wraps the Django TestCase class?
Django uses this
_database_namesmethod: https://github.com/django/django/blob/ab2f5f764a2f6db97e23cccd5c4f5abbb43d1caf/django/test/testcases.py#L869-L877I have tried the following:
With
--reuse-dbI am getting this error on teardown:With
--create-dbit results in: