Skip to content

Commit 392d8cb

Browse files
committed
Node: do not add "::()" to nodeid
Fixes pytest-dev#4127.
1 parent b92530d commit 392d8cb

File tree

5 files changed

+17
-23
lines changed

5 files changed

+17
-23
lines changed

src/_pytest/nodes.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _splitnode(nodeid):
2727
''
2828
'testing/code'
2929
'testing/code/test_excinfo.py'
30-
'testing/code/test_excinfo.py::TestFormattedExcinfo::()'
30+
'testing/code/test_excinfo.py::TestFormattedExcinfo'
3131
3232
Return values are lists e.g.
3333
[]
@@ -39,15 +39,15 @@ def _splitnode(nodeid):
3939
# If there is no root node at all, return an empty list so the caller's logic can remain sane
4040
return []
4141
parts = nodeid.split(SEP)
42-
# Replace single last element 'test_foo.py::Bar::()' with multiple elements 'test_foo.py', 'Bar', '()'
42+
# Replace single last element 'test_foo.py::Bar' with multiple elements 'test_foo.py', 'Bar'
4343
parts[-1:] = parts[-1].split("::")
4444
return parts
4545

4646

4747
def ischildnode(baseid, nodeid):
4848
"""Return True if the nodeid is a child node of the baseid.
4949
50-
E.g. 'foo/bar::Baz::()' is a child of 'foo', 'foo/bar' and 'foo/bar::Baz', but not of 'foo/blorp'
50+
E.g. 'foo/bar::Baz' is a child of 'foo', 'foo/bar' and 'foo/bar::Baz', but not of 'foo/blorp'
5151
"""
5252
base_parts = _splitnode(baseid)
5353
node_parts = _splitnode(nodeid)
@@ -107,10 +107,12 @@ def __init__(
107107
self._name2pseudofixturedef = {}
108108

109109
if nodeid is not None:
110+
assert "::()" not in nodeid
110111
self._nodeid = nodeid
111112
else:
112-
assert parent is not None
113-
self._nodeid = self.parent.nodeid + "::" + self.name
113+
self._nodeid = self.parent.nodeid
114+
if self.name != "()":
115+
self._nodeid += "::" + self.name
114116

115117
@property
116118
def ihook(self):

src/_pytest/runner.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ def pytest_terminal_summary(terminalreporter):
6060
tr.write_line("")
6161
tr.write_line("(0.00 durations hidden. Use -vv to show these durations.)")
6262
break
63-
nodeid = rep.nodeid.replace("::()::", "::")
64-
tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, nodeid))
63+
tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, rep.nodeid))
6564

6665

6766
def pytest_sessionstart(session):

src/_pytest/terminal.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -602,9 +602,7 @@ def _printcollecteditems(self, items):
602602
self._tw.line("%s: %d" % (name, count))
603603
else:
604604
for item in items:
605-
nodeid = item.nodeid
606-
nodeid = nodeid.replace("::()::", "::")
607-
self._tw.line(nodeid)
605+
self._tw.line(item.nodeid)
608606
return
609607
stack = []
610608
indent = ""
@@ -684,7 +682,7 @@ def mkrel(nodeid):
684682
# collect_fspath comes from testid which has a "/"-normalized path
685683

686684
if fspath:
687-
res = mkrel(nodeid).replace("::()", "") # parens-normalization
685+
res = mkrel(nodeid)
688686
if self.verbosity >= 2 and nodeid.split("::")[0] != fspath.replace(
689687
"\\", nodes.SEP
690688
):

testing/test_collection.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,8 @@ def test_method(self):
510510
pass
511511
"""
512512
)
513-
normid = p.basename + "::TestClass::()::test_method"
514-
for id in [
515-
p.basename,
516-
p.basename + "::TestClass",
517-
p.basename + "::TestClass::()",
518-
normid,
519-
]:
513+
normid = p.basename + "::TestClass::test_method"
514+
for id in [p.basename, p.basename + "::TestClass", normid]:
520515
items, hookrec = testdir.inline_genitems(id)
521516
assert len(items) == 1
522517
assert items[0].name == "test_method"
@@ -625,7 +620,7 @@ def test_method(self):
625620
items, hookrec = testdir.inline_genitems(arg)
626621
assert len(items) == 1
627622
item, = items
628-
assert item.nodeid.endswith("TestClass::()::test_method")
623+
assert item.nodeid.endswith("TestClass::test_method")
629624
# ensure we are reporting the collection of the single test item (#2464)
630625
assert [x.name for x in self.get_reported_items(hookrec)] == ["test_method"]
631626

testing/test_nodes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
("", "", True),
99
("", "foo", True),
1010
("", "foo/bar", True),
11-
("", "foo/bar::TestBaz::()", True),
11+
("", "foo/bar::TestBaz", True),
1212
("foo", "food", False),
13-
("foo/bar::TestBaz::()", "foo/bar", False),
14-
("foo/bar::TestBaz::()", "foo/bar::TestBop::()", False),
15-
("foo/bar", "foo/bar::TestBop::()", True),
13+
("foo/bar::TestBaz", "foo/bar", False),
14+
("foo/bar::TestBaz", "foo/bar::TestBop", False),
15+
("foo/bar", "foo/bar::TestBop", True),
1616
),
1717
)
1818
def test_ischildnode(baseid, nodeid, expected):

0 commit comments

Comments
 (0)