Skip to content

iter_markers order is top-to-bottom at module node/scope #7597

@iwanb

Description

@iwanb

Not entirely sure if it would be considered a bug, but it surprised me. I expect iter_markers to return the markers in bottom-to-top order (outwards from the test), but for the pytestmark variable this is not the case, it returns them in the list order.

import pytest

pytestmark = [
    pytest.mark.order(4),
    pytest.mark.order(3),
]

@pytest.mark.order(2)
@pytest.mark.order(1)
def test_marker(request):
    lowest = 0
    for mark in request.node.iter_markers("order"):
        order = mark.args[0]
        assert order > lowest
        lowest = order
FAILED test_marker.py::test_marker - assert 3 > 4

I expect this will also apply for pytestmark as a class variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: marksrelated to marks, either the general marks or builtin

    Type

    No type

    Projects

    Status

    To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions