Skip to content

Update the docs when overriding django_db_setup #1190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -334,15 +334,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")

for connection in connections.all():
connection.close()
Expand All @@ -365,14 +365,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")


Populate the database with initial test data
Expand Down