Skip to content

Commit

Permalink
Node: do not add "::()" to nodeid
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Nov 9, 2018
1 parent b92530d commit 392d8cb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
12 changes: 7 additions & 5 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _splitnode(nodeid):
''
'testing/code'
'testing/code/test_excinfo.py'
'testing/code/test_excinfo.py::TestFormattedExcinfo::()'
'testing/code/test_excinfo.py::TestFormattedExcinfo'
Return values are lists e.g.
[]
Expand All @@ -39,15 +39,15 @@ def _splitnode(nodeid):
# If there is no root node at all, return an empty list so the caller's logic can remain sane
return []
parts = nodeid.split(SEP)
# Replace single last element 'test_foo.py::Bar::()' with multiple elements 'test_foo.py', 'Bar', '()'
# Replace single last element 'test_foo.py::Bar' with multiple elements 'test_foo.py', 'Bar'
parts[-1:] = parts[-1].split("::")
return parts


def ischildnode(baseid, nodeid):
"""Return True if the nodeid is a child node of the baseid.
E.g. 'foo/bar::Baz::()' is a child of 'foo', 'foo/bar' and 'foo/bar::Baz', but not of 'foo/blorp'
E.g. 'foo/bar::Baz' is a child of 'foo', 'foo/bar' and 'foo/bar::Baz', but not of 'foo/blorp'
"""
base_parts = _splitnode(baseid)
node_parts = _splitnode(nodeid)
Expand Down Expand Up @@ -107,10 +107,12 @@ def __init__(
self._name2pseudofixturedef = {}

if nodeid is not None:
assert "::()" not in nodeid
self._nodeid = nodeid
else:
assert parent is not None
self._nodeid = self.parent.nodeid + "::" + self.name
self._nodeid = self.parent.nodeid
if self.name != "()":
self._nodeid += "::" + self.name

@property
def ihook(self):
Expand Down
3 changes: 1 addition & 2 deletions src/_pytest/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ def pytest_terminal_summary(terminalreporter):
tr.write_line("")
tr.write_line("(0.00 durations hidden. Use -vv to show these durations.)")
break
nodeid = rep.nodeid.replace("::()::", "::")
tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, nodeid))
tr.write_line("%02.2fs %-8s %s" % (rep.duration, rep.when, rep.nodeid))


def pytest_sessionstart(session):
Expand Down
6 changes: 2 additions & 4 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,7 @@ def _printcollecteditems(self, items):
self._tw.line("%s: %d" % (name, count))
else:
for item in items:
nodeid = item.nodeid
nodeid = nodeid.replace("::()::", "::")
self._tw.line(nodeid)
self._tw.line(item.nodeid)
return
stack = []
indent = ""
Expand Down Expand Up @@ -684,7 +682,7 @@ def mkrel(nodeid):
# collect_fspath comes from testid which has a "/"-normalized path

if fspath:
res = mkrel(nodeid).replace("::()", "") # parens-normalization
res = mkrel(nodeid)
if self.verbosity >= 2 and nodeid.split("::")[0] != fspath.replace(
"\\", nodes.SEP
):
Expand Down
11 changes: 3 additions & 8 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,8 @@ def test_method(self):
pass
"""
)
normid = p.basename + "::TestClass::()::test_method"
for id in [
p.basename,
p.basename + "::TestClass",
p.basename + "::TestClass::()",
normid,
]:
normid = p.basename + "::TestClass::test_method"
for id in [p.basename, p.basename + "::TestClass", normid]:
items, hookrec = testdir.inline_genitems(id)
assert len(items) == 1
assert items[0].name == "test_method"
Expand Down Expand Up @@ -625,7 +620,7 @@ def test_method(self):
items, hookrec = testdir.inline_genitems(arg)
assert len(items) == 1
item, = items
assert item.nodeid.endswith("TestClass::()::test_method")
assert item.nodeid.endswith("TestClass::test_method")
# ensure we are reporting the collection of the single test item (#2464)
assert [x.name for x in self.get_reported_items(hookrec)] == ["test_method"]

Expand Down
8 changes: 4 additions & 4 deletions testing/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
("", "", True),
("", "foo", True),
("", "foo/bar", True),
("", "foo/bar::TestBaz::()", True),
("", "foo/bar::TestBaz", True),
("foo", "food", False),
("foo/bar::TestBaz::()", "foo/bar", False),
("foo/bar::TestBaz::()", "foo/bar::TestBop::()", False),
("foo/bar", "foo/bar::TestBop::()", True),
("foo/bar::TestBaz", "foo/bar", False),
("foo/bar::TestBaz", "foo/bar::TestBop", False),
("foo/bar", "foo/bar::TestBop", True),
),
)
def test_ischildnode(baseid, nodeid, expected):
Expand Down

0 comments on commit 392d8cb

Please sign in to comment.