66from collections .abc import Generator , Iterable , Sequence
77from contextlib import AbstractContextManager , contextmanager
88from functools import partial
9- from typing import TYPE_CHECKING , Any , Callable , Literal , Optional , Protocol , Union
9+ from typing import TYPE_CHECKING , Protocol
1010
1111import pytest
1212
1616
1717
1818if TYPE_CHECKING :
19+ from typing import Any , Callable , Literal , Optional , Union
20+
1921 import django
2022 import django .test
2123
2224 from . import DjangoDbBlocker
25+ from .django_compat import _User , _UserModel
2326
24-
25- _DjangoDbDatabases = Optional [Union [Literal ["__all__" ], Iterable [str ]]]
26- _DjangoDbAvailableApps = Optional [list [str ]]
27- # transaction, reset_sequences, databases, serialized_rollback, available_apps
28- _DjangoDb = tuple [bool , bool , _DjangoDbDatabases , bool , _DjangoDbAvailableApps ]
27+ _DjangoDbDatabases = Optional [Union [Literal ["__all__" ], Iterable [str ]]]
28+ _DjangoDbAvailableApps = Optional [list [str ]]
29+ # transaction, reset_sequences, databases, serialized_rollback, available_apps
30+ _DjangoDb = tuple [bool , bool , _DjangoDbDatabases , bool , _DjangoDbAvailableApps ]
2931
3032
3133__all__ = [
@@ -75,15 +77,15 @@ def django_db_modify_db_settings_xdist_suffix(request: pytest.FixtureRequest) ->
7577
7678@pytest .fixture (scope = "session" )
7779def django_db_modify_db_settings_parallel_suffix (
78- django_db_modify_db_settings_tox_suffix : None ,
79- django_db_modify_db_settings_xdist_suffix : None ,
80+ django_db_modify_db_settings_tox_suffix : None , # noqa: ARG001
81+ django_db_modify_db_settings_xdist_suffix : None , # noqa: ARG001
8082) -> None :
8183 skip_if_no_django ()
8284
8385
8486@pytest .fixture (scope = "session" )
8587def django_db_modify_db_settings (
86- django_db_modify_db_settings_parallel_suffix : None ,
88+ django_db_modify_db_settings_parallel_suffix : None , # noqa: ARG001
8789) -> None :
8890 """Modify db settings just before the databases are configured."""
8991 skip_if_no_django ()
@@ -162,12 +164,12 @@ def _get_databases_for_setup(
162164@pytest .fixture (scope = "session" )
163165def django_db_setup (
164166 request : pytest .FixtureRequest ,
165- django_test_environment : None ,
167+ django_test_environment : None , # noqa: ARG001
166168 django_db_blocker : DjangoDbBlocker ,
167169 django_db_use_migrations : bool ,
168170 django_db_keepdb : bool ,
169171 django_db_createdb : bool ,
170- django_db_modify_db_settings : None ,
172+ django_db_modify_db_settings : None , # noqa: ARG001
171173) -> Generator [None , None , None ]:
172174 """Top level fixture to ensure test databases are available"""
173175 from django .test .utils import setup_databases , teardown_databases
@@ -350,7 +352,7 @@ def __getitem__(self, item: str) -> None:
350352 settings .MIGRATION_MODULES = DisableMigrations ()
351353
352354 class MigrateSilentCommand (migrate .Command ):
353- def handle (self , * args , ** kwargs ) :
355+ def handle (self , * args : Any , ** kwargs : Any ) -> Any :
354356 kwargs ["verbosity" ] = 0
355357 return super ().handle (* args , ** kwargs )
356358
@@ -474,26 +476,26 @@ def async_client() -> django.test.AsyncClient:
474476
475477
476478@pytest .fixture
477- def django_user_model (db : None ):
479+ def django_user_model (db : None ) -> _UserModel : # noqa: ARG001
478480 """The class of Django's user model."""
479481 from django .contrib .auth import get_user_model
480482
481- return get_user_model ()
483+ return get_user_model () # type: ignore[no-any-return]
482484
483485
484486@pytest .fixture
485- def django_username_field (django_user_model ) -> str :
487+ def django_username_field (django_user_model : _UserModel ) -> str :
486488 """The fieldname for the username used with Django's user model."""
487489 field : str = django_user_model .USERNAME_FIELD
488490 return field
489491
490492
491493@pytest .fixture
492494def admin_user (
493- db : None ,
494- django_user_model ,
495+ db : None , # noqa: ARG001
496+ django_user_model : _User ,
495497 django_username_field : str ,
496- ):
498+ ) -> _User :
497499 """A Django admin user.
498500
499501 This uses an existing user with username "admin", or creates a new one with
@@ -521,8 +523,8 @@ def admin_user(
521523
522524@pytest .fixture
523525def admin_client (
524- db : None ,
525- admin_user ,
526+ db : None , # noqa: ARG001
527+ admin_user : _User ,
526528) -> django .test .Client :
527529 """A Django test client logged in as an admin user."""
528530 from django .test import Client
@@ -568,14 +570,14 @@ def __delattr__(self, attr: str) -> None:
568570
569571 self ._to_restore .append (override )
570572
571- def __setattr__ (self , attr : str , value ) -> None :
573+ def __setattr__ (self , attr : str , value : Any ) -> None :
572574 from django .test import override_settings
573575
574576 override = override_settings (** {attr : value })
575577 override .enable ()
576578 self ._to_restore .append (override )
577579
578- def __getattr__ (self , attr : str ):
580+ def __getattr__ (self , attr : str ) -> Any :
579581 from django .conf import settings
580582
581583 return getattr (settings , attr )
@@ -588,7 +590,7 @@ def finalize(self) -> None:
588590
589591
590592@pytest .fixture
591- def settings ():
593+ def settings () -> Generator [ SettingsWrapper , None , None ] :
592594 """A Django settings object which restores changes after the testrun"""
593595 skip_if_no_django ()
594596
@@ -598,7 +600,9 @@ def settings():
598600
599601
600602@pytest .fixture (scope = "session" )
601- def live_server (request : pytest .FixtureRequest ):
603+ def live_server (
604+ request : pytest .FixtureRequest ,
605+ ) -> Generator [live_server_helper .LiveServer , None , None ]:
602606 """Run a live Django server in the background during tests
603607
604608 The address the server is started from is taken from the
0 commit comments