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

Skip to content

Commit f1faec7

Browse files
author
Alexey Bogdanov
committed
fixed issue with left bracket in path to test file
1 parent 1fa5490 commit f1faec7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pythonFiles/testing_tools/adapter/pytest/_pytest_item.py

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

436436

437+
def _find_left_bracket(nodeid):
438+
"""Return tuple of path before test name, separator [, and test name.
439+
440+
If path looks like
441+
'dirname[sometext]/dirname/testfile.py::testset[testname]'
442+
then partition returns the first left bracket - and extension crashes"""
443+
bracketcount = 0
444+
for index in range(len(nodeid) - 1, -1, -1):
445+
char = nodeid[index]
446+
if char == ']':
447+
bracketcount += 1
448+
elif char == '[':
449+
bracketcount -= 1
450+
if bracketcount == 0:
451+
return nodeid[:index], nodeid[index], nodeid[index + 1:]
452+
return nodeid, '', ''
453+
454+
437455
def _iter_nodes(
438456
testid,
439457
kind,
@@ -448,7 +466,7 @@ def _iter_nodes(
448466
testid = "." + _pathsep + testid
449467

450468
if kind == "function" and nodeid.endswith("]"):
451-
funcid, sep, parameterized = nodeid.partition("[")
469+
funcid, sep, parameterized = _find_left_bracket(nodeid)
452470
if not sep:
453471
raise should_never_reach_here(
454472
nodeid,

0 commit comments

Comments
 (0)
0