Skip to content

Commit 3b080d0

Browse files
author
Lode Rosseel
committed
Fix type hinting
1 parent 1c3f7cd commit 3b080d0

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

pytest_django/fixtures.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,14 @@ def django_db_setup(
205205

206206

207207
def _build_pytest_django_test_case(
208-
test_case_class,
208+
test_case_class: type[django.test.TestCase],
209209
*,
210210
reset_sequences: bool,
211211
serialized_rollback: bool,
212-
databases,
213-
available_apps,
212+
databases: _DjangoDbDatabases,
213+
available_apps: _DjangoDbAvailableApps,
214214
skip_django_testcase_class_setup: bool,
215-
):
215+
) -> type[django.test.TestCase]:
216216
# Build a custom TestCase subclass with configured attributes and optional
217217
# overrides to skip Django's TestCase class-level setup/teardown.
218218
import django.test # local import to avoid hard dependency at import time
@@ -319,10 +319,7 @@ def _sync_django_db_helper(
319319
import pytest_asyncio
320320
except ImportError:
321321

322-
async def _async_django_db_helper(
323-
request: pytest.FixtureRequest,
324-
django_db_blocker: DjangoDbBlocker,
325-
) -> AsyncGenerator[None, None]:
322+
async def _async_django_db_helper() -> AsyncGenerator[None, None]:
326323
raise RuntimeError(
327324
"The `pytest_asyncio` plugin is required to use the `async_django_db` fixture."
328325
)
@@ -406,9 +403,9 @@ def _get_django_db_settings(request: pytest.FixtureRequest) -> _DjangoDb:
406403
@pytest.fixture
407404
def _django_db_helper(
408405
request: pytest.FixtureRequest,
409-
django_db_setup: None,
410-
django_db_blocker: DjangoDbBlocker,
411-
):
406+
django_db_setup: None, # noqa: ARG001
407+
django_db_blocker: DjangoDbBlocker, # noqa: ARG001
408+
) -> None:
412409
asyncio_marker = request.node.get_closest_marker("asyncio")
413410
transactional, *_ = _get_django_db_settings(request)
414411
if transactional or not asyncio_marker:

pytest_django/plugin.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ def _blocking_wrapper(self, *args: Any, **kwargs: Any) -> NoReturn: # noqa: ARG
844844
'"db" or "transactional_db" fixtures to enable it. '
845845
)
846846

847-
def _unblocked_async_only(self, wrapper_self: Any, *args, **kwargs):
847+
def _unblocked_async_only(self, wrapper_self: Any, *args: Any, **kwargs: Any) -> None:
848848
__tracebackhide__ = True
849849
from asgiref.sync import SyncToAsync
850850

@@ -860,23 +860,12 @@ def _unblocked_async_only(self, wrapper_self: Any, *args, **kwargs):
860860
if self._real_ensure_connection is not None:
861861
self._real_ensure_connection(wrapper_self, *args, **kwargs)
862862

863-
def _unblocked_sync_only(self, wrapper_self: Any, *args, **kwargs):
864-
__tracebackhide__ = True
865-
if threading.current_thread() != threading.main_thread():
866-
raise RuntimeError(
867-
"Database access is only allowed in the main thread, "
868-
"modify your test fixtures to be sync or use the transactional_db fixture."
869-
"See https://pytest-django.readthedocs.io/en/latest/database.html#db-thread-safeguards for more information."
870-
)
871-
if self._real_ensure_connection is not None:
872-
self._real_ensure_connection(wrapper_self, *args, **kwargs)
873-
874-
def unblock(self, async_only=False) -> AbstractContextManager[None]:
863+
def unblock(self, async_only: bool = False) -> AbstractContextManager[None]:
875864
"""Enable access to the Django database."""
876865
self._save_active_wrapper()
877866
if async_only:
878867

879-
def _method(wrapper_self, *args, **kwargs):
868+
def _method(wrapper_self: Any, *args: Any, **kwargs: Any) -> None:
880869
return self._unblocked_async_only(wrapper_self, *args, **kwargs)
881870

882871
self._dj_db_wrapper.ensure_connection = _method

0 commit comments

Comments
 (0)