Skip to content

Fix regression: pull in all databases instead of default database#1193

Closed
xi wants to merge 1 commit into
pytest-dev:mainfrom
xi:fix-all-databases
Closed

Fix regression: pull in all databases instead of default database#1193
xi wants to merge 1 commit into
pytest-dev:mainfrom
xi:fix-all-databases

Conversation

@xi
Copy link
Copy Markdown

@xi xi commented Apr 14, 2025

fixes #1192

@xi xi force-pushed the fix-all-databases branch from 98e1628 to dc8aa0d Compare April 14, 2025 15:36
Comment thread pytest_django/fixtures.py
@@ -147,9 +147,7 @@ def _get_databases_for_test(test: pytest.Item) -> tuple[Iterable[str], bool]:
databases = None
else:
return (), False
Copy link
Copy Markdown

@terencehonles terencehonles May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code path is also problematic, and what I am running into since the test itself isn't decorated with anything so the fixtures list does not include any that are mentioned above.

Comment thread tests/test_database.py
from django.test import TestCase
from .app.models import Item, SecondItem

TestCase.databases = ["default", "second"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bluetech is this something we want to support?

I thought the pytest_django-way was to use @pytest.mark.django_db(databases={"default", "second"})

@bluetech
Copy link
Copy Markdown
Member

I don't think we should make this change as it deviates from Django's behavior -- the default is to only request the default database as described here: https://docs.djangoproject.com/en/6.0/topics/testing/tools/#multi-database-support

The actual problem is the extra dynamism that pytest enables and you are taking advantage of (using fixtures instead of statically declaring the databases). I will discuss this more in the issue.

@bluetech bluetech closed this Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No way to specify the database for fixtures

4 participants