From 4ad6649829710ebd942f17b1d1d4545f2d59c2d4bf5023ce6f11d79e238a2fe9 Mon Sep 17 00:00:00 2001 From: Matej Cepl Date: Tue, 9 Jul 2024 15:33:36 +0000 Subject: [PATCH] - Add duplicated-markers.patch to fix some testsuites broken by that issue. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:pytest/python-pytest-asyncio?expand=0&rev=46 --- duplicated-markers.patch | 86 +++++++++++++++++++++++++++++++++++ python-pytest-asyncio.changes | 6 +++ python-pytest-asyncio.spec | 2 + 3 files changed, 94 insertions(+) create mode 100644 duplicated-markers.patch diff --git a/duplicated-markers.patch b/duplicated-markers.patch new file mode 100644 index 0000000..7b83d5a --- /dev/null +++ b/duplicated-markers.patch @@ -0,0 +1,86 @@ +From b646cc18a222c8043433c38a42c07245fe9735ce Mon Sep 17 00:00:00 2001 +From: Michael Seifert +Date: Sun, 19 May 2024 14:00:57 +0200 +Subject: [PATCH] [fix] Fixed a bug that causes markers to be duplicated for + async test functions. + +Signed-off-by: Michael Seifert +--- + docs/source/reference/changelog.rst | 9 ++++++++ + pytest_asyncio/plugin.py | 3 ++- + tests/markers/test_function_scope.py | 31 ++++++++++++++++++++++++++++ + 3 files changed, 42 insertions(+), 1 deletion(-) + +diff --git a/docs/source/reference/changelog.rst b/docs/source/reference/changelog.rst +index a55fb9a8..5f0de0a1 100644 +--- a/docs/source/reference/changelog.rst ++++ b/docs/source/reference/changelog.rst +@@ -2,6 +2,15 @@ + Changelog + ========= + ++0.23.8 (UNRELEASED) ++=================== ++- Fixes a bug that caused duplicate markers in async tests `#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 `_ +diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py +index cd4c4ede..d3d1fcf7 100644 +--- a/pytest_asyncio/plugin.py ++++ b/pytest_asyncio/plugin.py +@@ -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( +diff --git a/tests/markers/test_function_scope.py b/tests/markers/test_function_scope.py +index 2057a128..eded4552 100644 +--- a/tests/markers/test_function_scope.py ++++ b/tests/markers/test_function_scope.py +@@ -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) diff --git a/python-pytest-asyncio.changes b/python-pytest-asyncio.changes index f715afb..16aabcf 100644 --- a/python-pytest-asyncio.changes +++ b/python-pytest-asyncio.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Tue Jul 9 13:43:10 UTC 2024 - Markéta Machová + +- Add duplicated-markers.patch to fix some testsuites broken by + that issue. + ------------------------------------------------------------------- Thu Jun 6 20:26:26 UTC 2024 - Dirk Müller diff --git a/python-pytest-asyncio.spec b/python-pytest-asyncio.spec index 9e1d400..319049a 100644 --- a/python-pytest-asyncio.spec +++ b/python-pytest-asyncio.spec @@ -32,6 +32,8 @@ Summary: Pytest support for asyncio License: Apache-2.0 URL: https://github.com/pytest-dev/pytest-asyncio Source: https://github.com/pytest-dev/pytest-asyncio/archive/v%{version}.tar.gz#/pytest-asyncio-%{version}.tar.gz +# PATCH-FIX-UPSTREAM https://github.com/pytest-dev/pytest-asyncio/pull/838 Fix duplication of markers in async tests +Patch: duplicated-markers.patch BuildRequires: %{python_module base >= 3.8} BuildRequires: %{python_module pip} BuildRequires: %{python_module setuptools_scm}