Skip to content

Commit 90371af

Browse files
committed
[fix] Fixed a bug that causes markers to be duplicated for async test functions.
Signed-off-by: Michael Seifert <[email protected]>
1 parent eb63d5a commit 90371af

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pytest_asyncio/plugin.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ def _from_function(cls, function: Function, /) -> Function:
392392
Instantiates this specific PytestAsyncioFunction type from the specified
393393
Function item.
394394
"""
395-
assert function.get_closest_marker("asyncio")
395+
asyncio_marker = function.get_closest_marker("asyncio")
396+
assert asyncio_marker
396397
subclass_instance = cls.from_parent(
397398
function.parent,
398399
name=function.name,
@@ -402,7 +403,7 @@ def _from_function(cls, function: Function, /) -> Function:
402403
keywords=function.keywords,
403404
originalname=function.originalname,
404405
)
405-
subclass_instance.own_markers.extend(function.own_markers)
406+
subclass_instance.own_markers.append(asyncio_marker)
406407
subclassed_function_signature = inspect.signature(subclass_instance.obj)
407408
if "event_loop" in subclassed_function_signature.parameters:
408409
subclass_instance.warn(

tests/markers/test_function_scope.py

+21
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,24 @@ async def test_anything():
197197
)
198198
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
199199
result.assert_outcomes(warnings=0, passed=1)
200+
201+
202+
def test_asyncio_mark_does_not_duplicate_other_marks_in_auto_mode(
203+
pytester: Pytester,
204+
):
205+
pytester.makepyfile(
206+
dedent(
207+
"""\
208+
import pytest
209+
210+
@pytest.mark.dummy_marker
211+
async def test_markers_not_duplicated(request):
212+
markers = []
213+
for node, marker in request.node.iter_markers_with_node():
214+
markers.append(marker)
215+
assert len(markers) == 2
216+
"""
217+
)
218+
)
219+
result = pytester.runpytest_subprocess("--asyncio-mode=auto")
220+
result.assert_outcomes(warnings=0, passed=1)

0 commit comments

Comments
 (0)