Skip to content

Commit

Permalink
fixed issue with left bracket in path to test file (#17357)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Sep 23, 2021
1 parent 7847a25 commit a68f98f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions news/2 Fixes/17461.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Changed the way of searching left bracket [ in case of subsets of tests.
(thanks [ilexei](https://github.com/ilexei))
28 changes: 27 additions & 1 deletion pythonFiles/testing_tools/adapter/pytest/_pytest_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<test-case-name>].
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,
Expand All @@ -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,
Expand Down

0 comments on commit a68f98f

Please sign in to comment.