8000 fixed #17461 issue with left bracket in path to test file · ilexei/vscode-python@7111bc4 · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7111bc4

Browse files
Alexey Bogdanovilexei
Alexey Bogdanov
authored andcommitted
fixed microsoft#17461 issue with left bracket in path to test file
1 parent 1fa5490 commit 7111bc4

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pythonFiles/testing_tools/adapter/pytest/_pytest_item.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,32 @@ def _parse_node_id(
434434
)
435435

436436

437+
def _find_left_bracket(nodeid):
438+
"""Return tuple of part before final bracket open, separator [, and the remainder.
439+
Notes:
440+
Testcase names in case of parametrized tests are wrapped in [<test-case-name>].
441+
Examples:
442+
dirname[sometext]/dirname/testfile.py::testset::testname[testcase]
443+
=> ('dirname[sometext]/dirname/testfile.py::testset::testname', '[', 'testcase]')
444+
dirname/dirname/testfile.py::testset::testname[testcase]
445+
=> ('dirname/dirname/testfile.py::testset::testname', '[', 'testcase]')
446+
dirname/dirname/testfile.py::testset::testname[testcase[x]]
447+
=> ('dirname/dirname/testfile.py::testset::testname', '[', 'testcase[x]]')
448+
"""
449+
if not nodeid.endswith("]"):
450+
return nodeid, "", ""
451+
bracketcount = 0
452+
for index, char in enumerate(nodeid[::-1]):
453+
if char == "]":
454+
bracketcount += 1
455+
elif char == "[":
456+
bracketcount -= 1
457+
if bracketcount == 0:
458+
n = len(nodeid) - 1 - index
459+
return nodeid[:n], nodeid[n], nodeid[n + 1 :]
460+
return nodeid, "", ""
461+
462+
437463
def _iter_nodes(
438464
testid,
439465
kind,
@@ -448,7 +474,7 @@ def _iter_nodes(
448474
testid = "." + _pathsep + testid
449475

450476
if kind == "function" and nodeid.endswith("]"):
451-
funcid, sep, parameterized = nodeid.partition("[")
477+
funcid, sep, parameterized = _find_left_bracket(nodeid)
452478
if not sep:
453479
raise should_never_reach_here(
454480
nodeid,

0 commit comments

Comments
 (0)
0