From 2992e8a4382121bed897e1e490913ea955ed0d3d Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Wed, 29 Oct 2025 10:38:17 +0100 Subject: [PATCH 1/5] Basic test --- tests/test_initialization.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_initialization.py b/tests/test_initialization.py index 631a41ed..3bc0ca5b 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -60,3 +60,30 @@ def test_ds(): ] ) assert result.ret == 0 + + +def test_django_setup_dependency_load(django_pytester: DjangoPytester, monkeypatch: pytest.MonkeyPatch) -> None: + monkeypatch.setenv("DJANGO_SETTINGS_MODULE", "tpkg.settings_dev") + pkg = pytester.mkpydir("tpkg") + pkg.joinpath("settings_dev.py").write_text( + dedent( + """ + SOME_VARIABLE = "real" + """ + ) + ) + pkg.joinpath("settings_test.py").write_text( + dedent( + """ + SOME_VARIABLE = "fake" + """ + ) + ) + django_pytester.makepyfile( + """ + def test_ds(settings): + assert settings.SOME_VARIABLE == "fake" + """ + ) + result = django_pytester.runpytest_subprocess("-s", "-ds", "tpkg.settings_test") + assert result.ret == 0 \ No newline at end of file From 16ad3bb031179b251c09b250b4416f44da60a510 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Wed, 29 Oct 2025 10:40:10 +0100 Subject: [PATCH 2/5] . --- tests/test_initialization.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_initialization.py b/tests/test_initialization.py index 3bc0ca5b..94aa7faa 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -1,4 +1,5 @@ from textwrap import dedent +import pytest from .helpers import DjangoPytester @@ -86,4 +87,4 @@ def test_ds(settings): """ ) result = django_pytester.runpytest_subprocess("-s", "-ds", "tpkg.settings_test") - assert result.ret == 0 \ No newline at end of file + assert result.ret == 0 From 596b1a3809e97314f3156e4fcf52e739185b1efd Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Wed, 29 Oct 2025 10:42:40 +0100 Subject: [PATCH 3/5] Speeds up tests, fixes imports --- tests/test_initialization.py | 2 +- tox.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_initialization.py b/tests/test_initialization.py index 94aa7faa..55d0821e 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -63,7 +63,7 @@ def test_ds(): assert result.ret == 0 -def test_django_setup_dependency_load(django_pytester: DjangoPytester, monkeypatch: pytest.MonkeyPatch) -> None: +def test_django_setup_dependency_load(pytester: pytest.Pytester, django_pytester: DjangoPytester, monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("DJANGO_SETTINGS_MODULE", "tpkg.settings_dev") pkg = pytester.mkpydir("tpkg") pkg.joinpath("settings_dev.py").write_text( diff --git a/tox.ini b/tox.ini index 5ffeeead..1d238bcc 100644 --- a/tox.ini +++ b/tox.ini @@ -37,7 +37,7 @@ passenv = PYTEST_ADDOPTS,TERM,TEST_DB_USER,TEST_DB_PASSWORD,TEST_DB_HOST usedevelop = True commands = coverage: coverage erase - {env:PYTESTDJANGO_TEST_RUNNER:pytest} {posargs:tests} + {env:PYTESTDJANGO_TEST_RUNNER:pytest} {posargs:tests} tests/test_initialization.py coverage: coverage combine coverage: coverage report coverage: coverage xml From 41c86d4c7bf55a1b56f2564685be2a1f8d3b7e48 Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Wed, 29 Oct 2025 11:22:41 +0100 Subject: [PATCH 4/5] . --- tests/test_initialization.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_initialization.py b/tests/test_initialization.py index 55d0821e..f59ec106 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -63,7 +63,7 @@ def test_ds(): assert result.ret == 0 -def test_django_setup_dependency_load(pytester: pytest.Pytester, django_pytester: DjangoPytester, monkeypatch: pytest.MonkeyPatch) -> None: +def test_django_setup_dependency_load(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("DJANGO_SETTINGS_MODULE", "tpkg.settings_dev") pkg = pytester.mkpydir("tpkg") pkg.joinpath("settings_dev.py").write_text( @@ -80,11 +80,13 @@ def test_django_setup_dependency_load(pytester: pytest.Pytester, django_pytester """ ) ) - django_pytester.makepyfile( - """ - def test_ds(settings): - assert settings.SOME_VARIABLE == "fake" - """ + pkg.joinpath("settings_test.py").write_text( + dedent( + """ + def test_ds(settings): + assert settings.SOME_VARIABLE == "fake" + """ + ) ) - result = django_pytester.runpytest_subprocess("-s", "-ds", "tpkg.settings_test") + result = pytester.runpytest_subprocess("-s", "-ds", "tpkg.settings_test") assert result.ret == 0 From b3f7963bd75fd0cfac8e35871de6879d3dc3247d Mon Sep 17 00:00:00 2001 From: Javier Buzzi Date: Wed, 29 Oct 2025 11:24:29 +0100 Subject: [PATCH 5/5] . --- tests/test_initialization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_initialization.py b/tests/test_initialization.py index f59ec106..9c2f99f7 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -63,9 +63,9 @@ def test_ds(): assert result.ret == 0 -def test_django_setup_dependency_load(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) -> None: +def test_django_setup_dependency_load(pytester: pytest.Pytester, django_pytester: DjangoPytester, monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setenv("DJANGO_SETTINGS_MODULE", "tpkg.settings_dev") - pkg = pytester.mkpydir("tpkg") + pkg = pytester.joinpath("tpkg") pkg.joinpath("settings_dev.py").write_text( dedent( """ @@ -88,5 +88,5 @@ def test_ds(settings): """ ) ) - result = pytester.runpytest_subprocess("-s", "-ds", "tpkg.settings_test") + result = django_pytester.runpytest_subprocess("-s", "-ds", "tpkg.settings_test") assert result.ret == 0