pytest-dev / pytest-dev/pytest-django

Teardown drops database if used in combination with live_server

Open
#1,051 1 comment 0 reactions 0 assignees View on GitHub

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.