|
21 | 21 | Literal,
|
22 | 22 | Optional,
|
23 | 23 | Set,
|
| 24 | + Type, |
24 | 25 | TypeVar,
|
25 | 26 | Union,
|
26 | 27 | overload,
|
@@ -365,18 +366,19 @@ class PytestAsyncioFunction(Function):
|
365 | 366 | """Base class for all test functions managed by pytest-asyncio."""
|
366 | 367 |
|
367 | 368 | @classmethod
|
368 |
| - def substitute(cls, item: Function, /) -> Function: |
| 369 | + def item_subclass_for( |
| 370 | + cls, item: Function, / |
| 371 | + ) -> Union[Type["PytestAsyncioFunction"], None]: |
369 | 372 | """
|
370 |
| - Returns a PytestAsyncioFunction if there is an implementation that can handle |
371 |
| - the specified function item. |
| 373 | + Returns a subclass of PytestAsyncioFunction if there is a specialized subclass |
| 374 | + for the specified function item. |
372 | 375 |
|
373 |
| - If no implementation of PytestAsyncioFunction can handle the specified item, |
374 |
| - the item is returned unchanged. |
| 376 | + Return None if no specialized subclass exists for the specified item. |
375 | 377 | """
|
376 | 378 | for subclass in cls.__subclasses__():
|
377 | 379 | if subclass._can_substitute(item):
|
378 |
| - return subclass._from_function(item) |
379 |
| - return item |
| 380 | + return subclass |
| 381 | + return None |
380 | 382 |
|
381 | 383 | @classmethod
|
382 | 384 | def _from_function(cls, function: Function, /) -> Function:
|
@@ -535,7 +537,9 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
|
535 | 537 | for node in node_iterator:
|
536 | 538 | updated_item = node
|
537 | 539 | if isinstance(node, Function):
|
538 |
| - updated_item = PytestAsyncioFunction.substitute(node) |
| 540 | + specialized_item_class = PytestAsyncioFunction.item_subclass_for(node) |
| 541 | + if specialized_item_class: |
| 542 | + updated_item = specialized_item_class._from_function(node) |
539 | 543 | updated_node_collection.append(updated_item)
|
540 | 544 |
|
541 | 545 | hook_result.force_result(updated_node_collection)
|
|
0 commit comments