Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions docs/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ Put this into ``conftest.py``::


@pytest.fixture(scope='session')
def django_db_setup():
def django_db_setup(request):
from django.conf import settings

settings.DATABASES['default']['NAME'] = 'the_copied_db'

run_sql('DROP DATABASE IF EXISTS the_copied_db')
run_sql('CREATE DATABASE the_copied_db TEMPLATE the_source_db')

yield
yield request.getfixturevalue("django_db_setup")
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

This creates a circular dependency where django_db_setup tries to get its own fixture value. The correct approach would be to yield from the original fixture or use a different fixture name for the override.

Suggested change
yield request.getfixturevalue("django_db_setup")
yield

Copilot uses AI. Check for mistakes.


for connection in connections.all():
connection.close()
Expand All @@ -359,14 +359,16 @@ Put this into ``conftest.py``::


@pytest.fixture(scope='session')
def django_db_setup():
def django_db_setup(request):
from django.conf import settings

settings.DATABASES['default'] = {
'ENGINE': 'django.db.backends.mysql',
'HOST': 'db.example.com',
'NAME': 'external_db',
}
# Do NOT override the whole `settings.DATABASES['default'] = {..}`
# as this could lead to errors.
settings.DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
settings.DATABASES['default']['HOST'] = 'db.example.com'
settings.DATABASES['default']['NAME'] = 'external_db'

yield request.getfixturevalue("django_db_setup")
Copy link

Copilot AI Aug 13, 2025

Choose a reason for hiding this comment

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

This creates a circular dependency where django_db_setup tries to get its own fixture value. The correct approach would be to yield from the original fixture or use a different fixture name for the override.

Suggested change
yield request.getfixturevalue("django_db_setup")
yield from original_django_db_setup(request)

Copilot uses AI. Check for mistakes.



Populate the database with initial test data
Expand Down