Skip to content

Commit 6aea28b

Browse files
committed
Use nodeid instead of dot notation of relative markers
- closes #24
1 parent a3c9bc0 commit 6aea28b

File tree

8 files changed

+27
-40
lines changed

8 files changed

+27
-40
lines changed

CHANGELOG.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
## Unreleased
44

5-
_Breaking changes in next major version_:
6-
With that version the notation of relative markers in other modules is also
7-
planned to change - instead of using the dot notation, the standard pytest
8-
nodeid will be used.
9-
105
### Breaking changes
116
- removed support for Python 2.7 and 3.5
7+
- changed notation of relative markers in other modules - instead of using
8+
the dot notation, the standard pytest nodeid is used,
9+
see [#24](https://github.com/pytest-dev/pytest-order/issues/24)
1210

1311
## [Version 0.11.0](https://pypi.org/project/pytest-order/0.11.0/) (2021-04-11)
1412
Adds support for multiple relative markers for the same test.

docs/source/index.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,11 @@ with a ``::`` suffix has to be prepended to the test name:
356356
def test_c(self):
357357
assert True
358358
359-
If the referenced test lives in another module, the test name has to be
360-
prepended by the module path to be uniquely identifiable. Let's say we have
361-
the following module and test layout:
359+
If the referenced test lives in another module, you have to use the nodeid
360+
of the test, or a part of the nodeid that is sufficient to make it uniquely
361+
identifiable (the nodeid is the test ID that pytest prints if you run it with
362+
the ``-v`` option).
363+
Let's say we have the following module and test layout:
362364

363365
::
364366

@@ -383,11 +385,11 @@ modules, this could be expressed like:
383385
384386
import pytest
385387
386-
@pytest.mark.order(after="test_module_a.TestA::test_a")
388+
@pytest.mark.order(after="test_module_a.py::TestA::test_a")
387389
def test_a():
388390
assert True
389391
390-
@pytest.mark.order(before="test_module_c.test_submodule.test_2")
392+
@pytest.mark.order(before="test_module_c/test_submodule.py::test_2")
391393
def test_b():
392394
assert True
393395
@@ -466,15 +468,15 @@ attributes by using a list or tuple of test names:
466468
467469
import pytest
468470
469-
@pytest.mark.order(after=["test_second", "other_module.test_other"])
471+
@pytest.mark.order(after=["test_second", "other_module.py::test_other"])
470472
def test_first():
471473
assert True
472474
473475
def test_second():
474476
assert True
475477
476478
This will ensure that ``test_first`` is executed both after ``test_second``
477-
and after ``test_other`` which resides in the module ``other_module``.
479+
and after ``test_other`` which resides in the module ``other_module.py``.
478480

479481
Configuration
480482
=============
@@ -784,7 +786,7 @@ Here is a similar example using relative markers:
784786
785787
import pytest
786788
787-
@pytest.mark.order(after="test_module2.test1")
789+
@pytest.mark.order(after="test_module2.py::test1")
788790
def test1():
789791
pass
790792

example/test_modules_b.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import pytest
55

66

7-
@pytest.mark.order(after="test_module_a.TestA::test_a")
7+
@pytest.mark.order(after="test_module_a.py::TestA::test_a")
88
def test_a():
99
assert True
1010

1111

12-
@pytest.mark.order(before="test_module_c.test_submodule.test_2")
12+
@pytest.mark.order(before="test_module_c.py::test_submodule.test_2")
1313
def test_b():
1414
assert True

pytest_order/item.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ def node_id(self) -> str:
3737
self._node_id = self.item.nodeid.replace("::()", "")
3838
return self._node_id
3939

40-
@property
41-
def label(self) -> str:
42-
return self.node_id.replace(".py::", ".").replace("/", ".")
43-
4440

4541
class ItemList:
4642
"""Handles a group of items with the same scope."""
@@ -99,8 +95,8 @@ def sort_numbered_items(self) -> List[Item]:
9995
return sorted_list
10096

10197
def print_unhandled_items(self):
102-
msg = " ".join([mark.item.label for mark in self.rel_marks] +
103-
[mark.item.label for mark in self.dep_marks])
98+
msg = " ".join([mark.item.node_id for mark in self.rel_marks] +
99+
[mark.item.node_id for mark in self.dep_marks])
104100
if msg:
105101
sys.stdout.write(
106102
"\nWARNING: cannot execute test relative to others: ")

pytest_order/sorter.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def item_from_label(
141141
self, label: str,
142142
item: Item,
143143
is_cls_mark: bool) -> Optional[Item]:
144-
label = self.node_id_from_label(label)
145144
item_id = item.node_id
146145
label_len = len(label)
147146
last_comp = label.split("/")[-1].split("::")[-1]
@@ -159,7 +158,6 @@ def item_from_label(
159158

160159
def items_from_class_label(self, label: str, item: Item) -> List[Item]:
161160
items = []
162-
label = self.node_id_from_label(label)
163161
item_id = item.node_id
164162
label_len = len(label)
165163
for node_id in self.node_ids:
@@ -171,13 +169,6 @@ def items_from_class_label(self, label: str, item: Item) -> List[Item]:
171169
items.append(self.node_ids[node_id])
172170
return items
173171

174-
@staticmethod
175-
def node_id_from_label(label: str) -> str:
176-
if "." in label:
177-
label_comp = label.split(".")
178-
label = ".py::".join(["/".join(label_comp[:-1]), label_comp[-1]])
179-
return label
180-
181172
def handle_before_or_after_mark(
182173
self,
183174
item: Item,

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
description-file = README.md
33
license_files = LICENSE
44
[bdist_wheel]
5-
universal=1
5+
universal=0
66
[tool:pytest]
77
testpaths = tests

tests/test_order_group_scope_relative.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Test2:
2222
def test_one(self):
2323
assert True
2424
25-
@pytest.mark.order(after='test_rel3.test_two')
25+
@pytest.mark.order(after='test_rel3.py::test_two')
2626
def test_two(self):
2727
assert True
2828
""",
@@ -39,7 +39,7 @@ def test_two():
3939
def test_one():
4040
assert True
4141
42-
@pytest.mark.order(before='test_rel2.test_one')
42+
@pytest.mark.order(before='test_rel2.py::test_one')
4343
def test_two():
4444
assert True
4545
""",

tests/test_relative_ordering.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,11 @@ def fixture_path(test_path):
138138
import pytest
139139
140140
class TestA:
141-
@pytest.mark.order(after="mod2_test.TestB::test_b")
141+
@pytest.mark.order(after="mod2_test.py::TestB::test_b")
142142
def test_a(self):
143143
pass
144144
145-
@pytest.mark.order(after="sub.mod3_test.test_b")
145+
@pytest.mark.order(after="sub/mod3_test.py::test_b")
146146
def test_b(self):
147147
pass
148148
@@ -153,7 +153,7 @@ def test_c(self):
153153
import pytest
154154
155155
class TestB:
156-
@pytest.mark.order(before="mod1_test.TestA::test_c")
156+
@pytest.mark.order(before="mod1_test.py::TestA::test_c")
157157
def test_a(self):
158158
pass
159159
@@ -168,7 +168,7 @@ def test_c(self):
168168
path.write("""
169169
import pytest
170170
171-
@pytest.mark.order(before="mod2_test.TestB::test_c")
171+
@pytest.mark.order(before="mod2_test.py::TestB::test_c")
172172
def test_a():
173173
pass
174174
@@ -356,7 +356,7 @@ def test_dependency_after_unknown_test(item_names_for, capsys):
356356
test_content = """
357357
import pytest
358358
359-
@pytest.mark.order(after="some_module.test_2")
359+
@pytest.mark.order(after="some_module.py::test_2")
360360
def test_1():
361361
pass
362362
@@ -366,7 +366,7 @@ def test_2():
366366
assert item_names_for(test_content) == ["test_1", "test_2"]
367367
out, err = capsys.readouterr()
368368
warning = ("cannot execute test relative to others: "
369-
"some_module.test_2 - ignoring the marker")
369+
"some_module.py::test_2 - ignoring the marker")
370370
assert warning in out
371371

372372

@@ -434,5 +434,5 @@ def test_3():
434434
assert item_names_for(test_content) == ["test_2", "test_1", "test_3"]
435435
out, err = capsys.readouterr()
436436
warning = ("cannot execute test relative to others: "
437-
"test_dependency_loop.test_3")
437+
"test_dependency_loop.py::test_3")
438438
assert warning in out

0 commit comments

Comments
 (0)