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

Skip to content

Commit a68f98f

Browse files
ilexeiAlexey Bogdanovkarthiknadig
authored
fixed issue with left bracket in path to test file (#17357)
* fixed #17461 issue with left bracket in path to test file * added news for 17461 issue * Update news/2 Fixes/17461.md Co-authored-by: Karthik Nadig <kanadig@microsoft.com> Co-authored-by: Alexey Bogdanov <ilexei@yandex-team.ru> Co-authored-by: Karthik Nadig <kanadig@microsoft.com>
1 parent 7847a25 commit a68f98f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

news/2 Fixes/17461.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Changed the way of searching left bracket [ in case of subsets of tests.
2+
(thanks [ilexei](https://github.com/ilexei))

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