Skip to content

"db" fixture not found by _get_databases_for_test #1246

@bdauvergne

Description

@bdauvergne

Since #1186 (release 4.11.1 I think) during test runs when selecting only one test case it fails with postgresql error database X does not exist as it tries to access the normal X database name instead of the test_X which should have been initialized. My tests look like this:

# conftest.py

@pytest.fixture
def app(db):
    .....


# tests/test_something.py

class TestClass:
    @pytest.fixture
    def app(self, app): # LINE XXX
          .....

    def test_something(self, app):
          ......

If i run pytest with -k test_something pytest-django insists on accessing the database myapp instead of test_myapp which has been initialized. Neithe have been initialized anyway. I traced the problem in _get_databases_for_test() on these lines:

        fixtures = getattr(test, "fixturenames", ())
        ....
        elif "db" in fixtures or "transactional_db" in fixtures or "live_server" in fixtures:

db is never found in fixtures, but if I add 'db' to the fixture signature on LINE XXX in test_something.py, then it works. It seems pytest is not correctly reporting the fixtures from overridden fixtures, don't know it it's a bug in pytest or a misuse of pytest API by pytest-django.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions