pytest-dev / pytest-dev/pytest-django
Teardown drops database if used in combination with live_server
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
In my project, I have an integration test which uses its own prefilled database. This means that in conftest.py, I overwrote this fixture as:
@pytest.fixture
def django_db_setup():
pass
in order to prevent the database being created. This works fine until I introduced an end-to-end test using the fixture live_server. If this fixture is used, my database is dropped after all tests have finished. It of course is not very pleasant that a database is dropped by a 3rd party library which has been set up by someone else.
I haven't found any possibility to prevent dropping the database, since there is no fixture such as django_db_teardown which could be overridden.
I'm using Django-4.0.10, pytest-7.2.2, pytest-django-4.5.2.
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 in conftest.py by tracing how the overridden django_db_setup interacts with the live_server fixture and database cleanup. Reproduce the prefilled-database integration test, then run the relevant test suite and verify that using live_server no longer drops the database after all tests finish.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- database, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100