Skip to content

Commit d5d4960

Browse files
committed
[refactor] Simplified code for marking pytest.Items with "asyncio" in auto mode.
The implementation tests against the item type rather than testing against the test function itself. This prevents duplicate logic in identifying whether a test function is a staticmethod, a Hypothesis test, … Signed-off-by: Michael Seifert <[email protected]>
1 parent 6863959 commit d5d4960

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

pytest_asyncio/plugin.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
Collector,
3131
Config,
3232
FixtureRequest,
33-
Function,
3433
Item,
3534
Metafunc,
3635
Parser,
@@ -564,25 +563,16 @@ def pytest_collection_modifyitems(
564563
565564
The mark is only applied in `AUTO` mode. It is applied to:
566565
567-
- coroutines
568-
- staticmethods wrapping coroutines
566+
- coroutines and async generators
569567
- Hypothesis tests wrapping coroutines
568+
- staticmethods wrapping coroutines
570569
571570
"""
572571
if _get_asyncio_mode(config) != Mode.AUTO:
573572
return
574-
function_items = (item for item in items if isinstance(item, Function))
575-
for function_item in function_items:
576-
function = function_item.obj
577-
if isinstance(function, staticmethod):
578-
# staticmethods need to be unwrapped.
579-
function = function.__func__
580-
if (
581-
_is_coroutine(function)
582-
or _is_hypothesis_test(function)
583-
and _hypothesis_test_wraps_coroutine(function)
584-
):
585-
function_item.add_marker("asyncio")
573+
for item in items:
574+
if isinstance(item, (AsyncFunction, AsyncHypothesisTest, AsyncStaticMethod)):
575+
item.add_marker("asyncio")
586576

587577

588578
def _hypothesis_test_wraps_coroutine(function: Any) -> bool:

0 commit comments

Comments
 (0)