From 0233ec3bfb7084e432f0f40bee7a9c89d0ddd054 Mon Sep 17 00:00:00 2001 From: Vineet Singh <78719701+Vineet829@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:58:49 +0530 Subject: [PATCH 1/2] Apply chained relative markers between order groups --- CHANGELOG.md | 4 ++ src/pytest_order/sorter.py | 1 + tests/test_order_group_scope_relative.py | 57 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffbae41..1601862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ - 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 +- with `--order-group-scope`, relative and dependency markers between modules + or classes are resolved in repeated passes, so a chain such as A after C, + B after A is now applied; previously only one pass was made and part of such + a chain could be ignored without a warning ## [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", + ] + ) From 8564143094dbe63a38c0a2a156172e07c9b45f29 Mon Sep 17 00:00:00 2001 From: Vineet Singh <78719701+Vineet829@users.noreply.github.com> Date: Mon, 23 Nov 2026 06:11:29 +0530 Subject: [PATCH 2/2] Shorten the changelog entry for the group scope fix --- CHANGELOG.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1601862..ecca0f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,10 +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 -- with `--order-group-scope`, relative and dependency markers between modules - or classes are resolved in repeated passes, so a chain such as A after C, - B after A is now applied; previously only one pass was made and part of such - a chain could be ignored without a warning +- 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.