8000 fixed issue with left bracket in path to test file by ilexei · Pull Request #17357 · microsoft/vscode-python · GitHub
[go: up one dir, main page]

Skip to content

fixed issue with left bracket in path to test file #17357

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

Merged
merged 3 commits into from
Sep 23, 2021
Merged
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/17461.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Changed the way of searching left bracket [ in case of subsets of tests.
(thanks [ilexei](https://github.com/ilexei))
28 changes: 27 additions & 1 deletion pythonFiles/testing_tools/adapter/pytest/_pytest_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,32 @@ def _parse_node_id(
)


def _find_left_bracket(nodeid):
"""Return tuple of part before final bracket open, separator [, and the remainder.
Notes:
Testcase names in case of parametrized tests are wrapped in [<test-case-name>].
Examples:
dirname[sometext]/dirname/testfile.py::testset::testname[testcase]
=> ('dirname[sometext]/dirname/testfile.py::testset::testname', '[', 'testcase]')
dirname/dirname/testfile.py::testset::testname[testcase]
=> ('dirname/dirname/testfile.py::testset::testname', '[', 'testcase]')
dirname/dirname/testfile.py::testset::testname[testcase[x]]
=> ('dirname/dirname/testfile.py::testset::testname', '[', 'testcase[x]]')
"""
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, "", ""


def _iter_nodes(
testid,
kind,
Expand All @@ -448,7 +474,7 @@ def _iter_nodes(
testid = "." + _pathsep + testid

if kind == "function" and nodeid.endswith("]"):
funcid, sep, parameterized = nodeid.partition("[")
funcid, sep, parameterized = _find_left_bracket(nodeid)
if not sep:
raise should_never_reach_here(
nodeid,
Expand Down
0