Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iter_markers_with_node() has double entries for async test functions #813

Open
jvtm opened this issue Apr 13, 2024 · 3 comments
Open

iter_markers_with_node() has double entries for async test functions #813

jvtm opened this issue Apr 13, 2024 · 3 comments

Comments

@jvtm
Copy link

jvtm commented Apr 13, 2024

Description

With pytest-asyncio and async def test_...() function decorated with @pytest.mark.xyz each marker appears twice in request.node.iter_markers_with_node().

Environment

pip list

Package        Version
-------------- -------
iniconfig      2.0.0
packaging      24.0
pip            23.3.1
pluggy         1.4.0
pytest         8.1.1
pytest-asyncio 0.23.6

pytest.ini

[pytest]
log_level = INFO
markers = 
    network: Requires live network
    slow: Slow to execute
    smoke: Smoke tests
asyncio_mode = auto

OS / Python

  • cPython 3.12.2
  • Linux / amd64

Test

test_iter_markers.py

import logging

import pytest

logger = logging.getLogger("markerdebug")


def check_markers(request: pytest.FixtureRequest) -> None:
    markers = []
    marker_ids = set()
    for node, marker in request.node.iter_markers_with_node():
        logging.info(
            "node_id=%r node=%r marker_id=%r marker=%r",
            id(node),
            node,
            id(marker),
            marker,
        )
        markers.append(marker)
        marker_ids.add(id(marker))
    assert len(markers) == len(marker_ids)


@pytest.mark.slow
@pytest.mark.network
@pytest.mark.usefixtures("monkeypatch")
async def test_debug_iter_markers_async(request: pytest.FixtureRequest) -> None:
   check_markers(request) 


@pytest.mark.slow
@pytest.mark.network
@pytest.mark.usefixtures("monkeypatch")
def test_debug_iter_markers_sync(request: pytest.FixtureRequest) -> None:
    check_markers(request)

Output

============================================= test session starts =============================================
platform linux -- Python 3.12.2, pytest-8.1.1, pluggy-1.4.0
configfile: pytest.ini
plugins: asyncio-0.23.6
asyncio: mode=Mode.AUTO
collected 2 items                                                                                             

test_iter_markers.py F.                                                                                 [100%]

================================================== FAILURES ===================================================
________________________________________ test_debug_iter_markers_async ________________________________________

request = <FixtureRequest for <Coroutine test_debug_iter_markers_async>>

    @pytest.mark.slow
    @pytest.mark.network
    @pytest.mark.usefixtures("monkeypatch")
    async def test_debug_iter_markers_async(request: pytest.FixtureRequest) -> None:
>      check_markers(request)

test_iter_markers.py:28: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

...
>       assert len(markers) == len(marker_ids)
E       AssertionError: assert 7 == 4
E        +  where 7 = len([Mark(name='usefixtures', args=('monkeypatch',), kwargs={}), Mark(name='network', args=(), kwargs={}), Mark(name='slow...rgs=('monkeypatch',), kwargs={}), Mark(name='network', args=(), kwargs={}), Mark(name='slow', args=(), kwargs={}), ...])
E        +  and   4 = len({140114061819008, 140114061990688, 140114070935392, 140114075899504})

test_iter_markers.py:21: AssertionError
---------------------------------------------- Captured log call ----------------------------------------------
INFO     root:test_iter_markers.py:12 node_id=140114061847456 node=<Coroutine test_debug_iter_markers_async> marker_id=140114061990688 marker=Mark(name='usefixtures', args=('monkeypatch',), kwargs={})
INFO     root:test_iter_markers.py:12 node_id=140114061847456 node=<Coroutine test_debug_iter_markers_async> marker_id=140114070935392 marker=Mark(name='network', args=(), kwargs={})
INFO     root:test_iter_markers.py:12 node_id=140114061847456 node=<Coroutine test_debug_iter_markers_async> marker_id=140114061819008 marker=Mark(name='slow', args=(), kwargs={})
INFO     root:test_iter_markers.py:12 node_id=140114061847456 node=<Coroutine test_debug_iter_markers_async> marker_id=140114061990688 marker=Mark(name='usefixtures', args=('monkeypatch',), kwargs={})
INFO     root:test_iter_markers.py:12 node_id=140114061847456 node=<Coroutine test_debug_iter_markers_async> marker_id=140114070935392 marker=Mark(name='network', args=(), kwargs={})
INFO     root:test_iter_markers.py:12 node_id=140114061847456 node=<Coroutine test_debug_iter_markers_async> marker_id=140114061819008 marker=Mark(name='slow', args=(), kwargs={})
INFO     root:test_iter_markers.py:12 node_id=140114061847456 node=<Coroutine test_debug_iter_markers_async> marker_id=140114075899504 marker=Mark(name='asyncio', args=(), kwargs={})
=========================================== short test summary info ===========================================
FAILED test_iter_markers.py::test_debug_iter_markers_async - AssertionError: assert 7 == 4
========================================= 1 failed, 1 passed in 0.02s =========================================
(Pdb) pprint.pprint(markers)
[Mark(name='usefixtures', args=('monkeypatch',), kwargs={}),
 Mark(name='network', args=(), kwargs={}),
 Mark(name='slow', args=(), kwargs={}),
 Mark(name='usefixtures', args=('monkeypatch',), kwargs={}),
 Mark(name='network', args=(), kwargs={}),
 Mark(name='slow', args=(), kwargs={}),
 Mark(name='asyncio', args=(), kwargs={})]
@jvtm jvtm changed the title .iter_markers_with_node() has double entries for async test functions iter_markers_with_node() has double entries for async test functions Apr 13, 2024
@jvtm
Copy link
Author

jvtm commented Apr 13, 2024

(Pdb) pprint.pprint(request.node.own_markers)
[Mark(name='usefixtures', args=('monkeypatch',), kwargs={}),
 Mark(name='network', args=(), kwargs={}),
 Mark(name='slow', args=(), kwargs={}),
 Mark(name='usefixtures', args=('monkeypatch',), kwargs={}),
 Mark(name='network', args=(), kwargs={}),
 Mark(name='slow', args=(), kwargs={}),
 Mark(name='asyncio', args=(), kwargs={})]

@RonnyPfannschmidt
Copy link
Member

seems like this is a bug in pytest-asyncio

@RonnyPfannschmidt RonnyPfannschmidt transferred this issue from pytest-dev/pytest Apr 14, 2024
@RonnyPfannschmidt
Copy link
Member

subclass_instance.own_markers.extend(function.own_markers)
incorrectly adds the values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants