Skip to content

Commit 85a552b

Browse files
authored
The relative warning now specifies which test can't be sorted (#30)
* The relative warning now specifies which test can't be sorted * Adjust tests to match the warning change
1 parent 6aea28b commit 85a552b

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

pytest_order/sorter.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ def handle_before_or_after_mark(
177177
is_after: bool) -> bool:
178178
def is_class_mark() -> bool:
179179
return (
180-
item.item.cls and
181-
item.item.parent.get_closest_marker("order") == mark
180+
item.item.cls and
181+
item.item.parent.get_closest_marker("order") == mark
182182
)
183183

184184
def is_mark_for_class() -> bool:
@@ -219,7 +219,7 @@ def handle_relative_marks(self, item: Item, mark: Mark) -> bool:
219219
item, mark, before_mark, is_after=False):
220220
has_relative_marks = True
221221
else:
222-
self.warn_about_unknown_test(before_mark)
222+
self.warn_about_unknown_test(item, before_mark)
223223
after_marks = mark.kwargs.get("after", ())
224224
if after_marks and not isinstance(after_marks, (list, tuple)):
225225
after_marks = (after_marks,)
@@ -228,13 +228,15 @@ def handle_relative_marks(self, item: Item, mark: Mark) -> bool:
228228
item, mark, after_mark, is_after=True):
229229
has_relative_marks = True
230230
else:
231-
self.warn_about_unknown_test(after_mark)
231+
self.warn_about_unknown_test(item, after_mark)
232232
return has_relative_marks
233233

234234
@staticmethod
235-
def warn_about_unknown_test(rel_mark: str) -> None:
236-
sys.stdout.write("\nWARNING: cannot execute test relative to others:"
237-
" {} - ignoring the marker.".format(rel_mark))
235+
def warn_about_unknown_test(item: Item, rel_mark: str) -> None:
236+
sys.stdout.write(
237+
"\nWARNING: cannot execute '{}' relative to others: "
238+
"'{}' - ignoring the marker.".format(item.item.name, rel_mark)
239+
)
238240

239241
def collect_markers(self) -> None:
240242
aliases = {}

tests/test_class_marks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_2(self): pass
5959
"Test1::test_1", "Test1::test_2", "Test2::test_1", "Test2::test_2"
6060
]
6161
out, err = capsys.readouterr()
62-
assert ("WARNING: cannot execute test relative to others: Test3 "
62+
assert ("WARNING: cannot execute 'test_2' relative to others: 'Test3' "
6363
"- ignoring the marker" in out)
6464

6565

tests/test_order_group_scope_relative.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_session_scope(fixture_path):
6060
result = fixture_path.runpytest("-v")
6161
result.assert_outcomes(passed=10, failed=0)
6262
result.stdout.fnmatch_lines([
63-
"*invalid - ignoring the marker.*",
63+
"*'invalid' - ignoring the marker.*",
6464
"test_rel1.py::Test1::test_two PASSED",
6565
"test_rel1.py::Test2::test_one PASSED",
6666
"test_rel3.py::test_two PASSED",

tests/test_relative_ordering.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ def test_2():
365365
"""
366366
assert item_names_for(test_content) == ["test_1", "test_2"]
367367
out, err = capsys.readouterr()
368-
warning = ("cannot execute test relative to others: "
369-
"some_module.py::test_2 - ignoring the marker")
368+
warning = ("cannot execute 'test_1' relative to others: "
369+
"'some_module.py::test_2' - ignoring the marker")
370370
assert warning in out
371371

372372

@@ -386,8 +386,8 @@ def test_3():
386386
"""
387387
assert item_names_for(test_content) == ["test_1", "test_2", "test_3"]
388388
out, err = capsys.readouterr()
389-
warning = ("cannot execute test relative to others: "
390-
"test_4 - ignoring the marker")
389+
warning = ("cannot execute 'test_2' relative to others: "
390+
"'test_4' - ignoring the marker")
391391
assert warning in out
392392

393393

@@ -410,8 +410,8 @@ def test_3(self):
410410
"Test::test_1", "Test::test_2", "Test::test_3"
411411
]
412412
out, err = capsys.readouterr()
413-
warning = ("cannot execute test relative to others: "
414-
"test_4 - ignoring the marker")
413+
warning = ("cannot execute 'test_2' relative to others: "
414+
"'test_4' - ignoring the marker")
415415
assert warning in out
416416

417417

0 commit comments

Comments
 (0)