Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve iterparentnodeids to consume / parts until the first :: #8577

Merged
merged 4 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Omar Kohl
Omer Hadari
Ondřej Súkup
Oscar Benjamin
Parth Patel
Patrick Hayes
Pauli Virtanen
Pavel Karateev
Expand Down
3 changes: 3 additions & 0 deletions changelog/8509.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed issue where `TestCase.setUpClass` is not called when a test method has `/` in its name in versions of `pytest >=6.2.0`.

Paths only consider `/` parts of a patch until the first `::` in `iterparentnodeids`. Then `::` parts of a path are considered. Test cases for this were updated to reflect this change.
bluetech marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 22 additions & 12 deletions src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,33 @@ def iterparentnodeids(nodeid: str) -> Iterator[str]:
"testing/code/test_excinfo.py::TestFormattedExcinfo"
"testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source"

Note that :: parts are only considered at the last / component.
Note that / components are only considered until the first ::.
"""
pos = 0
sep = SEP
first_colons: Optional[int] = nodeid.find("::")
if first_colons == -1:
first_colons = None
# The root Session node - always present.
yield ""
# Eagerly consume SEP parts until first colons.
while True:
at = nodeid.find(sep, pos)
if at == -1 and sep == SEP:
sep = "::"
elif at == -1:
if nodeid:
yield nodeid
at = nodeid.find(SEP, pos, first_colons)
if at == -1:
break
else:
if at:
yield nodeid[:at]
pos = at + len(sep)
if at > 0:
yield nodeid[:at]
pos = at + len(SEP)
# Eagerly consume :: parts.
while True:
at = nodeid.find("::", pos)
if at == -1:
break
if at > 0:
yield nodeid[:at]
pos = at + len("::")
# The node ID itself.
if nodeid:
yield nodeid


def _imply_path(
Expand Down
6 changes: 4 additions & 2 deletions testing/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
("a/b/c", ["", "a", "a/b", "a/b/c"]),
("a/bbb/c::D", ["", "a", "a/bbb", "a/bbb/c", "a/bbb/c::D"]),
("a/b/c::D::eee", ["", "a", "a/b", "a/b/c", "a/b/c::D", "a/b/c::D::eee"]),
# :: considered only at the last component.
("::xx", ["", "::xx"]),
("a/b/c::D/d::e", ["", "a", "a/b", "a/b/c::D", "a/b/c::D/d", "a/b/c::D/d::e"]),
# / only considered until first ::
("a/b/c::D/d::e", ["", "a", "a/b", "a/b/c", "a/b/c::D/d", "a/b/c::D/d::e"]),
# : alone is not a separator.
("a/b::D:e:f::g", ["", "a", "a/b", "a/b::D:e:f", "a/b::D:e:f::g"]),
# / not considered if a part of a test name
("a/b::c/d::e[/test]", ["", "a", "a/b", "a/b::c/d", "a/b::c/d::e[/test]"]),
),
)
def test_iterparentnodeids(nodeid: str, expected: List[str]) -> None:
Expand Down