diff --git a/docs/changelog.rst b/docs/changelog.rst index 4683eeba..f54fad5a 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,14 @@ Changelog v4.12.1 (unreleased) -------------------- +Improvements +^^^^^^^^^^^^ + +* Re-export ``pytest_django.SettingsWrapper`` from the top-level + ``pytest_django`` namespace so the :fixture:`settings` fixture can be + type-annotated without reaching into ``pytest_django.fixtures`` + (`#1257 `__). + Bugfixes ^^^^^^^^ diff --git a/docs/helpers.rst b/docs/helpers.rst index 4d129dad..c93f363a 100644 --- a/docs/helpers.rst +++ b/docs/helpers.rst @@ -442,6 +442,13 @@ Example settings.USE_TZ = True assert settings.USE_TZ +If you use type annotations, you can annotate the fixture like this:: + + from pytest_django import SettingsWrapper + + def test_with_specific_settings(settings: SettingsWrapper): + ... + .. fixture:: django_assert_num_queries diff --git a/pytest_django/__init__.py b/pytest_django/__init__.py index e4bb08f5..95b8e77f 100644 --- a/pytest_django/__init__.py +++ b/pytest_django/__init__.py @@ -5,7 +5,7 @@ __version__ = "unknown" -from .fixtures import DjangoAssertNumQueries, DjangoCaptureOnCommitCallbacks +from .fixtures import DjangoAssertNumQueries, DjangoCaptureOnCommitCallbacks, SettingsWrapper from .plugin import DjangoDbBlocker @@ -13,5 +13,6 @@ "DjangoAssertNumQueries", "DjangoCaptureOnCommitCallbacks", "DjangoDbBlocker", + "SettingsWrapper", "__version__", ] diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 16a548d4..1f79040a 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -461,6 +461,13 @@ def test_set_non_existent(settings): ] ) + def test_settings_wrapper_is_publicly_reexported(self) -> None: + import pytest_django + from pytest_django.fixtures import SettingsWrapper as _Wrapper + + assert "SettingsWrapper" in pytest_django.__all__ + assert pytest_django.SettingsWrapper is _Wrapper + class TestLiveServer: @pytest.mark.skipif("PYTEST_XDIST_WORKER" in os.environ, reason="xdist in use")