Skip to content

Commit 52df77a

Browse files
committed
feat: re-export SettingsWrapper from pytest_django for typing (#1257)
1 parent 587b65f commit 52df77a

4 files changed

Lines changed: 24 additions & 1 deletion

File tree

docs/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ Changelog
44
v4.12.1 (unreleased)
55
--------------------
66

7+
Improvements
8+
^^^^^^^^^^^^
9+
10+
* Exposed :class:`~pytest_django.SettingsWrapper` from the top-level
11+
:mod:`pytest_django` namespace so the :fixture:`settings` fixture can be
12+
type-annotated without reaching into ``pytest_django.fixtures``
13+
(`#1257 <https://github.com/pytest-dev/pytest-django/issues/1257>`__).
14+
715
Bugfixes
816
^^^^^^^^
917

docs/helpers.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,13 @@ Example
442442
settings.USE_TZ = True
443443
assert settings.USE_TZ
444444

445+
If you use type annotations, you can annotate the fixture like this::
446+
447+
from pytest_django import SettingsWrapper
448+
449+
def test_with_specific_settings(settings: SettingsWrapper):
450+
...
451+
445452

446453
.. fixture:: django_assert_num_queries
447454

pytest_django/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
__version__ = "unknown"
66

77

8-
from .fixtures import DjangoAssertNumQueries, DjangoCaptureOnCommitCallbacks
8+
from .fixtures import DjangoAssertNumQueries, DjangoCaptureOnCommitCallbacks, SettingsWrapper
99
from .plugin import DjangoDbBlocker
1010

1111

1212
__all__ = [
1313
"DjangoAssertNumQueries",
1414
"DjangoCaptureOnCommitCallbacks",
1515
"DjangoDbBlocker",
16+
"SettingsWrapper",
1617
"__version__",
1718
]

tests/test_fixtures.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,13 @@ def test_set_non_existent(settings):
461461
]
462462
)
463463

464+
def test_settings_wrapper_is_publicly_reexported(self) -> None:
465+
import pytest_django
466+
from pytest_django.fixtures import SettingsWrapper as _Wrapper
467+
468+
assert "SettingsWrapper" in pytest_django.__all__
469+
assert pytest_django.SettingsWrapper is _Wrapper
470+
464471

465472
class TestLiveServer:
466473
@pytest.mark.skipif("PYTEST_XDIST_WORKER" in os.environ, reason="xdist in use")

0 commit comments

Comments
 (0)