Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- a test with multiple order markers is run once per marker even if it is
collected more than once, e.g. as a method inherited by several test classes;
previously only the first collected instance kept its order markers
- chained relative markers between modules or classes are applied when
`--order-group-scope` is used
(see [#279](https://github.com/pytest-dev/pytest-order/pull/279))

## [Version 1.5.0](https://pypi.org/project/pytest-order/1.5.0/) (2026-06-13)
Adds option to abort tests after a failed ordering.
Expand Down
1 change: 1 addition & 0 deletions src/pytest_order/sorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ def sorted_groups(self) -> tuple[int | None, list[ItemGroup]]:
still_left = length
self.handle_rel_marks(self.rel_marks)
self.handle_rel_marks(self.dep_marks)
length = len(self.rel_marks) + len(self.dep_marks)
return group_order, self.groups

def sort_by_ordinal_markers(self) -> int | None:
Expand Down
57 changes: 57 additions & 0 deletions tests/test_order_group_scope_relative.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,60 @@ def test_2(self): pass
"test_class_rel.py::Test1::test_1 PASSED",
]
)


def test_module_group_scope_relative_chain(test_path):
test_path.makepyfile(
test_chain1="""
import pytest

@pytest.mark.order(after="test_chain3.py::test_three")
def test_one(): pass
""",
test_chain2="""
import pytest

@pytest.mark.order(after="test_chain1.py::test_one")
def test_two(): pass
""",
test_chain3="""
def test_three(): pass
""",
)
result = test_path.runpytest("-v", "--order-group-scope=module")
result.assert_outcomes(passed=3, failed=0)
result.stdout.fnmatch_lines(
[
"test_chain3.py::test_three PASSED",
"test_chain1.py::test_one PASSED",
"test_chain2.py::test_two PASSED",
]
)


def test_class_group_scope_relative_chain(test_path):
test_path.makepyfile(
test_class_chain="""
import pytest

class Test1:
@pytest.mark.order(after="Test3::test_three")
def test_one(self): pass

class Test2:
@pytest.mark.order(after="Test1::test_one")
def test_two(self): pass

class Test3:
def test_three(self): pass
"""
)
result = test_path.runpytest("-v", "--order-group-scope=class")
result.assert_outcomes(passed=3, failed=0)
result.stdout.fnmatch_lines(
[
"test_class_chain.py::Test3::test_three PASSED",
"test_class_chain.py::Test1::test_one PASSED",
"test_class_chain.py::Test2::test_two PASSED",
]
)