pytest-django icon indicating copy to clipboard operation
pytest-django copied to clipboard

django_db_setup data only available before first tearDown

Open frruit opened this issue 5 years ago • 2 comments
trafficstars

Hi, Inside the conftest.py I have following configuration

@pytest.fixture(scope='session')
def django_db_setup(django_db_setup, django_db_blocker):
    with django_db_blocker.unblock():
        call_command('loaddata', 'tests/test_data/test_data1.json', database='default')
        call_command('loaddata', 'tests/test_data/test_data2.json', database='ipr')

As you can see i use two different DB's

However, test first test case has access to the populated data and is successful but all test cases after that have no data. After debugging I have figured out that the tearDown methods flushs the db and no loaddata occures anymore.

HELP, I need somebody :-)

frruit avatar Dec 04 '19 14:12 frruit

This is with transactional_db then I assume? It's a known issue, and there should be some discussion / more insight with others here probably already. Search for "serialized rollback" also maybe, which is meant to help with that IIRC.

blueyed avatar Dec 04 '19 20:12 blueyed

This will be fixed with #970, though you'd need to enable serialized rollbacks.

bluetech avatar Nov 30 '21 13:11 bluetech