pytest-dev / pytest-dev/pytest-django

Populating the database with data - are the docs wrong or my setup?

Open
#490 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation
Dominant language
Python
Stars
1.5k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

Hello,

the docs suggest an approach to populate the database with the initial data this way: http://pytest-django.readthedocs.io/en/latest/database.html#populate-the-database-with-initial-test-data

I created a small demonstrational app that uses exactly that approach. Unfortunately, I am not able to see the test data anywhere else except the first test case ran. In the first test case everything is okay. In the subsequent test cases, the data are gone from the database.

Am I doing something wrong? Here is the conftest: https://github.com/mpasternak/pytest-django-pytest-splinter-test/blob/master/demo1/demo1_app/conftest.py and here are my tests: https://github.com/mpasternak/pytest-django-pytest-splinter-test/blob/master/demo1/demo1_app/tests.py#L21

When I change the scope of the django_db_setup fixture to function, everything comes back to normal.

So, is this a bug or should I create a PR to update the documentation? Is it somehow related to this issue: https://github.com/pytest-dev/pytest-django/issues/329 ?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked database documentation, then inspect the referenced conftest.py and tests.py around line 21, comparing django_db_setup with function scope. Reproduce the differing behavior across test cases and compare it with issue #329; done means determining whether this is a fixture bug or a documentation/setup problem and recording the required correction.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
databases, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.