pytest-dev / pytest-dev/pytest-django
Data migrations: preserve data between fixture tests
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
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 !
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the shown parametrized pytest fixture with @pytest.mark.django_db, Django RunPython migrations, and the SQLite database in /dev/shm. Trace when the database is reset between fixture parameters and compare that with the requested post-test database inspection. Done means documenting or implementing a supported way to preserve migrated data between runs without breaking test isolation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python, sqlite
- Domain
- databases, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100