Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+167df28d.downstream.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Extend dependency on typing-extensions>=4.12 from Python<3.10 to Python<3.13.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dynamic = [
dependencies = [
"backports-asyncio-runner>=1.1,<2; python_version<'3.11'",
"pytest>=8.2,<9",
"typing-extensions>=4.12; python_version<'3.10'",
"typing-extensions>=4.12; python_version<'3.13'",
]
optional-dependencies.docs = [
"sphinx>=5.3",
Expand Down
18 changes: 8 additions & 10 deletions pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
Literal,
TypeVar,
Union,
cast,
overload,
)

Expand Down Expand Up @@ -60,6 +59,11 @@
else:
from backports.asyncio.runner import Runner

if sys.version_info >= (3, 13):
from typing import TypeIs
else:
from typing_extensions import TypeIs

_ScopeName = Literal["session", "package", "module", "class", "function"]
_R = TypeVar("_R", bound=Union[Awaitable[Any], AsyncIterator[Any]])
_P = ParamSpec("_P")
Expand Down Expand Up @@ -628,14 +632,9 @@ def _set_event_loop(loop: AbstractEventLoop | None) -> None:

@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_pyfunc_call(pyfuncitem: Function) -> object | None:
"""
Pytest hook called before a test case is run.

Wraps marked tests in a synchronous function
where the wrapped test coroutine is executed in an event loop.
"""
"""Pytest hook called before a test case is run."""
if pyfuncitem.get_closest_marker("asyncio") is not None:
if isinstance(pyfuncitem, PytestAsyncioFunction):
if is_async_test(pyfuncitem):
asyncio_mode = _get_asyncio_mode(pyfuncitem.config)
for fixname, fixtures in pyfuncitem._fixtureinfo.name2fixturedefs.items():
# name2fixturedefs is a dict between fixture name and a list of matching
Expand Down Expand Up @@ -698,7 +697,6 @@ def pytest_runtest_setup(item: pytest.Item) -> None:
marker = item.get_closest_marker("asyncio")
if marker is None or not is_async_test(item):
return
item = cast(PytestAsyncioFunction, item)
runner_fixture_id = f"_{item.loop_scope}_scoped_runner"
fixturenames = item.fixturenames # type: ignore[attr-defined]
if runner_fixture_id not in fixturenames:
Expand Down Expand Up @@ -831,7 +829,7 @@ def event_loop_policy() -> AbstractEventLoopPolicy:
return _get_event_loop_policy()


def is_async_test(item: Item) -> bool:
def is_async_test(item: Item) -> TypeIs[PytestAsyncioFunction]:
"""Returns whether a test item is a pytest-asyncio test"""
return isinstance(item, PytestAsyncioFunction)

Expand Down
Loading