Skip to content

Commit 41a566a

Browse files
committed
feat: Add information for type checkers to is_async_test to allow type narrowing.
1 parent 428ac2d commit 41a566a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pytest_asyncio/plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
else:
6161
from backports.asyncio.runner import Runner
6262

63+
if sys.version_info >= (3, 13):
64+
from typing import TypeIs
65+
else:
66+
from typing_extensions import TypeIs
67+
6368
_ScopeName = Literal["session", "package", "module", "class", "function"]
6469
_R = TypeVar("_R", bound=Union[Awaitable[Any], AsyncIterator[Any]])
6570
_P = ParamSpec("_P")
@@ -831,7 +836,7 @@ def event_loop_policy() -> AbstractEventLoopPolicy:
831836
return _get_event_loop_policy()
832837

833838

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

0 commit comments

Comments
 (0)