pytest-dev / pytest-dev/pytest
iter_markers order is top-to-bottom at module node/scope
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in the issue and trace request.node.iter_markers("order") for module-level pytestmark, then check whether class-level pytestmark follows the same path. Done means the marker sequence is bottom-to-top as expected while preserving the existing test-marker behavior; add or update coverage for the shown module and class cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100