Skip to content

Commit b646cc1

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 81c5032 commit b646cc1

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

docs/source/reference/changelog.rst

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
Changelog
33
=========
44

5+
0.23.8 (UNRELEASED)
6+
===================
7+
- Fixes a bug that caused duplicate markers in async tests `#813 <https://github.com/pytest-dev/pytest-asyncio/issues/813>`_
8+
9+
Known issues
10+
------------
11+
As of v0.23, pytest-asyncio attaches an asyncio event loop to each item of the test suite (i.e. session, packages, modules, classes, functions) and allows tests to be run in those loops when marked accordingly. Pytest-asyncio currently assumes that async fixture scope is correlated with the new event loop scope. This prevents fixtures from being evaluated independently from the event loop scope and breaks some existing test suites (see `#706`_). For example, a test suite may require all fixtures and tests to run in the same event loop, but have async fixtures that are set up and torn down for each module. If you're affected by this issue, please continue using the v0.21 release, until it is resolved.
12+
13+
514
0.23.7 (2024-05-19)
615
===================
716
- Silence deprecation warnings about unclosed event loops that occurred with certain CPython patch releases `#817 <https://github.com/pytest-dev/pytest-asyncio/pull/817>`_

pytest_asyncio/plugin.py

+2-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(

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)