pytest-dev / pytest-django

A Django plugin for pytest.
https://pytest-django.readthedocs.io/
Other
1.37k stars 344 forks source link

Data migrations: preserve data between fixture tests #1028

Open frague59 opened 2 years ago

frague59 commented 2 years ago

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:

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 !