8000 Updated _find_left_bracket function used in pytest discovery to fix bug by scwilbanks · Pull Request #17955 · microsoft/vscode-python · GitHub
[go: up one dir, main page]

Skip to content

Updated _find_left_bracket function used in pytest discovery to fix bug #17955

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/2 Fixes/17954.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Pytest test discovery no longer fails when there are not the same number of open and closed brackets in testcase name
(thanks [Smith Wilbanks](https://github.com/scwilbanks))
20 changes: 10 additions & 10 deletions pythonFiles/testing_tools/adapter/pytest/_pytest_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,16 @@ def _find_left_bracket(nodeid):
"""
if not nodeid.endswith("]"):
return nodeid, "", ""
bracketcount = 0
for index, char in enumerate(nodeid[::-1]):
if char == "]":
bracketcount += 1
elif char == "[":
bracketcount -= 1
if bracketcount == 0:
n = len(nodeid) - 1 - index
return nodeid[:n], nodeid[n], nodeid[n + 1 :]
return nodeid, "", ""

testname_testcase = nodeid.split("::")[-1]
nodeid_base = nodeid[: -len(testname_testcase)]
open_bracket_n = testname_testcase.find("[")

if open_bracket_n == -1:
return nodeid, "", ""

n = open_bracket_n + len(nodeid_base)
return nodeid[:n], nodeid[n], nodeid[n + 1 :]


def _iter_nodes(
Expand Down
0