From 2e012d7cd2ae27fc924a8b1e264bcb0379a5b56a Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Sun, 6 Apr 2025 14:37:28 -0400 Subject: [PATCH 1/4] Update database.rst --- docs/database.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/database.rst b/docs/database.rst index c4410a6a..c265010a 100644 --- a/docs/database.rst +++ b/docs/database.rst @@ -365,7 +365,7 @@ Put this into ``conftest.py``:: @pytest.fixture(scope='session') - def django_db_setup(): + def django_db_setup(requests): from django.conf import settings settings.DATABASES['default'] = { @@ -374,6 +374,8 @@ Put this into ``conftest.py``:: 'NAME': 'external_db', } + yield request.getfixturevalue("django_db_setup") + Populate the database with initial test data """""""""""""""""""""""""""""""""""""""""""" From 02f80728455d2b8c145355f5327c99b415bff878 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Sun, 6 Apr 2025 14:41:31 -0400 Subject: [PATCH 2/4] Update database.rst --- docs/database.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/database.rst b/docs/database.rst index c265010a..867039ad 100644 --- a/docs/database.rst +++ b/docs/database.rst @@ -334,7 +334,7 @@ Put this into ``conftest.py``:: @pytest.fixture(scope='session') - def django_db_setup(): + def django_db_setup(requests): from django.conf import settings settings.DATABASES['default']['NAME'] = 'the_copied_db' @@ -342,7 +342,7 @@ Put this into ``conftest.py``:: 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() From 0c5de8c18c80e69f9802965104d899012deb0ca2 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Sun, 6 Apr 2025 14:45:34 -0400 Subject: [PATCH 3/4] Update database.rst --- docs/database.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/database.rst b/docs/database.rst index 867039ad..a82dfeec 100644 --- a/docs/database.rst +++ b/docs/database.rst @@ -368,11 +368,11 @@ Put this into ``conftest.py``:: def django_db_setup(requests): 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") From bf4feea405f6d3a735c870ee65449760eca71d43 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Mon, 7 Apr 2025 04:47:21 -0400 Subject: [PATCH 4/4] Apply suggestions from code review (omg -- im an idiot) Co-authored-by: Ran Benita --- docs/database.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/database.rst b/docs/database.rst index a82dfeec..fb0b5712 100644 --- a/docs/database.rst +++ b/docs/database.rst @@ -334,7 +334,7 @@ Put this into ``conftest.py``:: @pytest.fixture(scope='session') - def django_db_setup(requests): + def django_db_setup(request): from django.conf import settings settings.DATABASES['default']['NAME'] = 'the_copied_db' @@ -365,7 +365,7 @@ Put this into ``conftest.py``:: @pytest.fixture(scope='session') - def django_db_setup(requests): + def django_db_setup(request): from django.conf import settings # Do NOT override the whole `settings.DATABASES['default'] = {..}`