From e209d42576f083779471509b3f50c0735d60f467 Mon Sep 17 00:00:00 2001 From: Smith Wilbanks Date: Sun, 7 Nov 2021 11:52:56 -0600 Subject: [PATCH 1/3] Updated _find_left_bracket function used in pytest discovery to fix bug --- .../adapter/pytest/_pytest_item.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py index 2c22db21d4de..0efe9734a706 100644 --- a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py +++ b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py @@ -448,16 +448,17 @@ 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( From 030e8c662d0d4d4577394681197b3ef8c0873f46 Mon Sep 17 00:00:00 2001 From: Smith Wilbanks Date: Sun, 7 Nov 2021 12:05:35 -0600 Subject: [PATCH 2/3] Added news entry --- news/2 Fixes/17954.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 news/2 Fixes/17954.md diff --git a/news/2 Fixes/17954.md b/news/2 Fixes/17954.md new file mode 100644 index 000000000000..e05ada9ea0ae --- /dev/null +++ b/news/2 Fixes/17954.md @@ -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)) \ No newline at end of file From 5fd861189ade4784bb4be0d941cc02907f3bbc2d Mon Sep 17 00:00:00 2001 From: Smith Wilbanks Date: Mon, 8 Nov 2021 07:06:55 -0600 Subject: [PATCH 3/3] Removed extra newline with black --- pythonFiles/testing_tools/adapter/pytest/_pytest_item.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py index 0efe9734a706..59b0cede937a 100644 --- a/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py +++ b/pythonFiles/testing_tools/adapter/pytest/_pytest_item.py @@ -458,7 +458,6 @@ def _find_left_bracket(nodeid): n = open_bracket_n + len(nodeid_base) return nodeid[:n], nodeid[n], nodeid[n + 1 :] - def _iter_nodes(