Skip to content

Commit

Permalink
[fix] Fixed a bug that causes markers to be duplicated for async test…
Browse files Browse the repository at this point in the history
… functions.

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
  • Loading branch information
seifertm committed Jul 8, 2024
1 parent 81c5032 commit b646cc1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/source/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
Changelog
=========

0.23.8 (UNRELEASED)
===================
- Fixes a bug that caused duplicate markers in async tests `#813 <https://github.com/pytest-dev/pytest-asyncio/issues/813>`_

Known issues
------------
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.


0.23.7 (2024-05-19)
===================
- Silence deprecation warnings about unclosed event loops that occurred with certain CPython patch releases `#817 <https://github.com/pytest-dev/pytest-asyncio/pull/817>`_
Expand Down
3 changes: 2 additions & 1 deletion pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ def _from_function(cls, function: Function, /) -> Function:
keywords=function.keywords,
originalname=function.originalname,
)
subclass_instance.own_markers.extend(function.own_markers)
subclass_instance.own_markers = function.own_markers
assert subclass_instance.own_markers == function.own_markers
subclassed_function_signature = inspect.signature(subclass_instance.obj)
if "event_loop" in subclassed_function_signature.parameters:
subclass_instance.warn(
Expand Down
31 changes: 31 additions & 0 deletions tests/markers/test_function_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,34 @@ async def test_anything():
)
result = pytester.runpytest_subprocess("--asyncio-mode=strict")
result.assert_outcomes(warnings=0, passed=1)


def test_asyncio_mark_does_not_duplicate_other_marks_in_auto_mode(
pytester: Pytester,
):
pytester.makeconftest(
dedent(
"""\
def pytest_configure(config):
config.addinivalue_line(
"markers", "dummy_marker: mark used for testing purposes"
)
"""
)
)
pytester.makepyfile(
dedent(
"""\
import pytest
@pytest.mark.dummy_marker
async def test_markers_not_duplicated(request):
markers = []
for node, marker in request.node.iter_markers_with_node():
markers.append(marker)
assert len(markers) == 2
"""
)
)
result = pytester.runpytest_subprocess("--asyncio-mode=auto")
result.assert_outcomes(warnings=0, passed=1)

0 comments on commit b646cc1

Please sign in to comment.