diff --git a/news/2 Fixes/17461.md b/news/2 Fixes/17461.md new file mode 100644 index 000000000000..5aa45710be3e --- /dev/null +++ b/news/2 Fixes/17461.md @@ -0,0 +1,2 @@ +Changed the way of searching left bracket [ in case of subsets of tests. +(thanks [ilexei](https://github.com/ilexei)) diff --git a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py index f9ed1fe0f289..2c22db21d4de 100644 --- a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py +++ b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py @@ -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 []. + 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, @@ -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,