From 5b8d1942604173c6b50ae342408b7f9f672ac8a2 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 14 Feb 2026 20:19:35 +0200 Subject: [PATCH] tests: make sure access to default can also be blocked --- pytest_django_test/settings_mysql.py | 1 + pytest_django_test/settings_postgres.py | 3 +++ pytest_django_test/settings_sqlite.py | 3 +++ pytest_django_test/settings_sqlite_file.py | 1 + tests/test_database.py | 5 +++++ 5 files changed, 13 insertions(+) diff --git a/pytest_django_test/settings_mysql.py b/pytest_django_test/settings_mysql.py index cb53559f..9288359e 100644 --- a/pytest_django_test/settings_mysql.py +++ b/pytest_django_test/settings_mysql.py @@ -45,6 +45,7 @@ "TEST": { "CHARSET": "utf8mb4", "COLLATION": "utf8mb4_unicode_ci", + "DEPENDENCIES": [], }, }, } diff --git a/pytest_django_test/settings_postgres.py b/pytest_django_test/settings_postgres.py index d5d7227b..1b5442d4 100644 --- a/pytest_django_test/settings_postgres.py +++ b/pytest_django_test/settings_postgres.py @@ -27,5 +27,8 @@ "USER": environ.get("TEST_DB_USER", ""), "PASSWORD": environ.get("TEST_DB_PASSWORD", ""), "HOST": environ.get("TEST_DB_HOST", ""), + "TEST": { + "DEPENDENCIES": [], + }, }, } diff --git a/pytest_django_test/settings_sqlite.py b/pytest_django_test/settings_sqlite.py index 039e49a9..e6273bbc 100644 --- a/pytest_django_test/settings_sqlite.py +++ b/pytest_django_test/settings_sqlite.py @@ -16,5 +16,8 @@ "second": { "ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:", + "TEST": { + "DEPENDENCIES": [], + }, }, } diff --git a/pytest_django_test/settings_sqlite_file.py b/pytest_django_test/settings_sqlite_file.py index d6cd36c4..e24f65fe 100644 --- a/pytest_django_test/settings_sqlite_file.py +++ b/pytest_django_test/settings_sqlite_file.py @@ -32,6 +32,7 @@ "NAME": "/pytest_django_tests_second", "TEST": { "NAME": _filename_second, + "DEPENDENCIES": [], }, }, } diff --git a/tests/test_database.py b/tests/test_database.py index cb5b54a0..bcb8dab5 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -325,6 +325,11 @@ def test_not_allowed_database(self) -> None: with pytest.raises(AssertionError, match="not allowed"): SecondItem.objects.create(name="spam") + @pytest.mark.django_db(databases=["second"]) + def test_not_allowed_database_non_default(self) -> None: + with pytest.raises(AssertionError, match="not allowed"): + Item.objects.create(name="spam") + @pytest.mark.django_db(databases=["replica"]) def test_replica_database(self) -> None: Item.objects.using("replica").count()