pytest-django
pytest-django copied to clipboard
Data migrations: preserve data between fixture tests
trafficstars
Hi,
I'm working on a app with default data migrations (some models are populated with the RunPython migration method, ie. default users, related models for select...).
I'm working on a test with data sets declares in a list of dicts, using a fixture with the request.param magic.
My fixture data looks like:
FIXTURE_DATA = [{"name": "Foo"}, {"name": "Bar"}...]
@pytest.fixture(scope="session", params=FIXTURE_DATA)
def data(request)
return request.param
@pytest.mark.django_db
def test_01_data(data):
# Make the stuff...
pass
Then I try to run the test, with a single fixture yielding my test data, the whole content of the database is freed between each fixture run:
- First data dict instance: OK
- Second data dict instance: The database structure is in place, but
RunPythonmigrated data are flushed... my test cannot continue.
I'm using a "droppable" sqlite file in /dev/shm, I'ld like to explore the content of the database after the tests - is it possible ?
Thanks !