Skip to content

Commit f3c89b0

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 9310655 commit f3c89b0

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

pytest_asyncio/plugin.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ def _from_function(cls, function: Function, /) -> Function:
405405
keywords=function.keywords,
406406
originalname=function.originalname,
407407
)
408-
subclass_instance.own_markers.extend(function.own_markers)
408+
subclass_instance.own_markers = function.own_markers
409+
assert subclass_instance.own_markers == function.own_markers
409410
subclassed_function_signature = inspect.signature(subclass_instance.obj)
410411
if "event_loop" in subclassed_function_signature.parameters:
411412
subclass_instance.warn(
@@ -553,6 +554,7 @@ def pytest_pycollect_makeitem_convert_async_functions_to_subclass(
553554
if _get_asyncio_mode(
554555
node.config
555556
) == Mode.AUTO and not node.get_closest_marker("asyncio"):
557+
print("Adding asyncio marker to " + node.nodeid)
556558
node.add_marker("asyncio")
557559
if node.get_closest_marker("asyncio"):
558560
updated_item = specialized_item_class._from_function(node)

tests/markers/test_function_scope.py

+31
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,34 @@ 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.makeconftest(
206+
dedent(
207+
"""\
208+
def pytest_configure(config):
209+
config.addinivalue_line(
210+
"markers", "dummy_marker: mark used for testing purposes"
211+
)
212+
"""
213+
)
214+
)
215+
pytester.makepyfile(
216+
dedent(
217+
"""\
218+
import pytest
219+
220+
@pytest.mark.dummy_marker
221+
async def test_markers_not_duplicated(request):
222+
markers = []
223+
for node, marker in request.node.iter_markers_with_node():
224+
markers.append(marker)
225+
assert len(markers) == 2
226+
"""
227+
)
228+
)
229+
result = pytester.runpytest_subprocess("--asyncio-mode=auto")
230+
result.assert_outcomes(warnings=0, passed=1)

0 commit comments

Comments
 (0)