From 7111bc4482cd2419245e2995bb335c422e4c2ccf Mon Sep 17 00:00:00 2001 From: Alexey Bogdanov Date: Fri, 10 Sep 2021 01:37:45 +0300 Subject: [PATCH 1/3] fixed #17461 issue with left bracket in path to test file --- .../adapter/pytest/_pytest_item.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) 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, From 449ec1ce7794b8d4613bc1bf8876507c3d2f2f08 Mon Sep 17 00:00:00 2001 From: Alexey Bogdanov Date: Tue, 21 Sep 2021 00:01:09 +0300 Subject: [PATCH 2/3] added news for 17461 issue --- news/2 Fixes/17461.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2 Fixes/17461.md diff --git a/news/2 Fixes/17461.md b/news/2 Fixes/17461.md new file mode 100644 index 000000000000..abb5caa0eb23 --- /dev/null +++ b/news/2 Fixes/17461.md @@ -0,0 +1 @@ +Changed the way of searching left bracket [ in case of subsets of tests. From dff04248b014e3c4d82614f78e2b74576fac48ca Mon Sep 17 00:00:00 2001 From: ilexei <32730766+ilexei@users.noreply.github.com> Date: Wed, 22 Sep 2021 13:06:22 +0300 Subject: [PATCH 3/3] Update news/2 Fixes/17461.md Co-authored-by: Karthik Nadig --- news/2 Fixes/17461.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/2 Fixes/17461.md b/news/2 Fixes/17461.md index abb5caa0eb23..5aa45710be3e 100644 --- a/news/2 Fixes/17461.md +++ b/news/2 Fixes/17461.md @@ -1 +1,2 @@ Changed the way of searching left bracket [ in case of subsets of tests. +(thanks [ilexei](https://github.com/ilexei))