Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/2 Fixes/17954.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Pytest test discovery no longer fails when there are not the same number of open and closed brackets in testcase name
(thanks [Smith Wilbanks](https://github.com/scwilbanks))
20 changes: 10 additions & 10 deletions pythonFiles/testing_tools/adapter/pytest/_pytest_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,16 @@ def _find_left_bracket(nodeid):
"""
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, "", ""

testname_testcase = nodeid.split("::")[-1]
nodeid_base = nodeid[: -len(testname_testcase)]
open_bracket_n = testname_testcase.find("[")

if open_bracket_n == -1:
return nodeid, "", ""

n = open_bracket_n + len(nodeid_base)
return nodeid[:n], nodeid[n], nodeid[n + 1 :]


def _iter_nodes(
Expand Down