Skip to content

Commit 1da3339

Browse files
committed
[refactor] Use "Function" type, instead of "pytest.Function".
Signed-off-by: Michael Seifert <[email protected]>
1 parent b9cdf0e commit 1da3339

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pytest_asyncio/plugin.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Collector,
3131
Config,
3232
FixtureRequest,
33+
Function,
3334
Item,
3435
Metafunc,
3536
Parser,
@@ -347,11 +348,11 @@ async def setup():
347348
fixturedef.func = _async_fixture_wrapper
348349

349350

350-
class PytestAsyncioFunction(pytest.Function):
351+
class PytestAsyncioFunction(Function):
351352
"""Base class for all test functions managed by pytest-asyncio."""
352353

353354
@classmethod
354-
def substitute(cls, item: pytest.Function, /) -> pytest.Function:
355+
def substitute(cls, item: Function, /) -> Function:
355356
"""
356357
Returns a PytestAsyncioFunction if there is an implementation that can handle
357358
the specified function item.
@@ -365,10 +366,10 @@ def substitute(cls, item: pytest.Function, /) -> pytest.Function:
365366
return item
366367

367368
@classmethod
368-
def _from_function(cls, function: pytest.Function, /) -> pytest.Function:
369+
def _from_function(cls, function: Function, /) -> Function:
369370
"""
370371
Instantiates this specific PytestAsyncioFunction type from the specified
371-
pytest.Function item.
372+
Function item.
372373
"""
373374
return cls.from_parent(
374375
function.parent,
@@ -381,7 +382,7 @@ def _from_function(cls, function: pytest.Function, /) -> pytest.Function:
381382
)
382383

383384
@staticmethod
384-
def _can_substitute(item: pytest.Function) -> bool:
385+
def _can_substitute(item: Function) -> bool:
385386
"""Returns whether the specified function can be replaced by this class"""
386387
raise NotImplementedError()
387388

@@ -390,7 +391,7 @@ class AsyncFunction(PytestAsyncioFunction):
390391
"""Pytest item that is a coroutine or an asynchronous generator"""
391392

392393
@staticmethod
393-
def _can_substitute(item: pytest.Function) -> bool:
394+
def _can_substitute(item: Function) -> bool:
394395
func = item.obj
395396
return _is_coroutine_or_asyncgen(func)
396397

@@ -409,7 +410,7 @@ class AsyncStaticMethod(PytestAsyncioFunction):
409410
"""
410411

411412
@staticmethod
412-
def _can_substitute(item: pytest.Function) -> bool:
413+
def _can_substitute(item: Function) -> bool:
413414
func = item.obj
414415
return isinstance(func, staticmethod) and _is_coroutine_or_asyncgen(
415416
func.__func__
@@ -430,7 +431,7 @@ class AsyncHypothesisTest(PytestAsyncioFunction):
430431
"""
431432

432433
@staticmethod
433-
def _can_substitute(item: pytest.Function) -> bool:
434+
def _can_substitute(item: Function) -> bool:
434435
func = item.obj
435436
return getattr(
436437
func, "is_hypothesis_test", False
@@ -486,7 +487,7 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
486487
updated_node_collection = []
487488
for node in node_iterator:
488489
updated_item = node
489-
if isinstance(node, pytest.Function):
490+
if isinstance(node, Function):
490491
updated_item = PytestAsyncioFunction.substitute(node)
491492
updated_node_collection.append(updated_item)
492493

@@ -716,7 +717,7 @@ def _provide_clean_event_loop() -> None:
716717

717718

718719
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
719-
def pytest_pyfunc_call(pyfuncitem: pytest.Function) -> Optional[object]:
720+
def pytest_pyfunc_call(pyfuncitem: Function) -> Optional[object]:
720721
"""
721722
Pytest hook called before a test case is run.
722723

0 commit comments

Comments
 (0)