pytest-django icon indicating copy to clipboard operation
pytest-django copied to clipboard

Typing support for `settings` fixture?

Open dave-v opened this issue 1 month ago • 2 comments

I couldn't find a documented way to type the settings fixture, but from digging through the source code, it looks like the pytest_django.fixtures.SettingsWrapper class is the most accurate choice.

I noticed that previously some of the fixtures were exposed for the purposes of typing, such as DjangoAssertNumQueries: https://github.com/pytest-dev/pytest-django/commit/16ee779d7abeb77e91bc98e9e3ea78f98c3a5d76.

Is there a particular reason settings was left out? Is there a recommended way to type annotate this? If it's just a case of applying a similar change to the commit above, I'm happy to contribute a PR.

dave-v avatar Dec 02 '25 12:12 dave-v

PRs welcome!

kingbuzzman avatar Dec 02 '25 14:12 kingbuzzman

Is there a preference for the public API?

The simplest choice looks like just adding SettingsWrapper to pytest_django.__init__.__all__, but the name feels a little unexpected. I think as a user of this library I'd expect the type annotation to look like one of the following:

def test_something(settings: SettingsFixture):
    ...

def test_something(settings: Settings):
    ...

Right now, I can import SettingsWrapper from pytest_django.fixtures directly, but this doesn't appear to follow the standard import pattern.

If you're happy with either Settings/SettingsFixture as the way forward, I'll work on a PR.

dave-v avatar Dec 02 '25 16:12 dave-v

Does it work with SettingsWrapper?

kingbuzzman avatar Dec 15 '25 16:12 kingbuzzman