diff --git a/CHANGELOG.md b/CHANGELOG.md index ffbae41..ecca0f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/pytest_order/sorter.py b/src/pytest_order/sorter.py index 4725e60..f01f39a 100644 --- a/src/pytest_order/sorter.py +++ b/src/pytest_order/sorter.py @@ -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: diff --git a/tests/test_order_group_scope_relative.py b/tests/test_order_group_scope_relative.py index 468d33f..a3eef33 100644 --- a/tests/test_order_group_scope_relative.py +++ b/tests/test_order_group_scope_relative.py @@ -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", + ] + )