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 2 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
1 change: 1 addition & 0 deletions changelog/8509.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue where `TestCase.setUpClass` is not called when a test method has `/` in its name in versions of `pytest >=6.2.0`.
11 changes: 10 additions & 1 deletion src/_pytest/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,16 @@ def iterparentnodeids(nodeid: str) -> Iterator[str]:
break
else:
if at:
yield nodeid[:at]
if sep == SEP:
colons_after_at = nodeid.find("::", at)
colons_before_at = nodeid.find("::", pos, at)
if colons_after_at > -1 or colons_before_at == -1:
yield nodeid[:at]
else:
sep = "::"
continue
else:
yield nodeid[:at]
pos = at + len(sep)


Expand Down
2 changes: 2 additions & 0 deletions testing/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
("a/b/c::D/d::e", ["", "a", "a/b", "a/b/c::D", "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::c", "a/b::c/d", "a/b::c/d::e[/test]"]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im under the impression a/b is missing as element

But thats for a follow-up as the same detail applies to other nodes as well

Copy link
Contributor Author

@parthdpa parthdpa Apr 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, but I believe that is apart of the functionality of the iterparentnodeids function because on line 65 of src/_pytest/nodes.py @bluetech put a comment that says

Note that :: parts are only considered at the last / component.

So that any :: between / would be considered as a part of the path.
Unless you mean this may need to be reconsidered, then I apologize for this comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i mean this may need a reconsideration much later, your pr is fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay. I understand. For this to be merged do I just wait for @bluetech to review it? I am new to the process, sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay. I understand. For this to be merged do I just wait for @bluetech to review it? I am new to the process, sorry.

Right -- I will try to review it today or tomorrow.

),
)
def test_iterparentnodeids(nodeid: str, expected: List[str]) -> None:
Expand Down