Skip to content

Commit 215c168

Browse files
Optimize pytest duplicate check from O(n) to O(1) using sets (#25658)
switched from list to set for better preformance was first done by copilot but ported over related to #25348 but about execution instead of discovery --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent 38e1cc6 commit 215c168

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

python_files/vscode_pytest/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(self, message):
7575
ERRORS = []
7676
IS_DISCOVERY = False
7777
map_id_to_path = {}
78-
collected_tests_so_far = []
78+
collected_tests_so_far = set()
7979
TEST_RUN_PIPE = os.getenv("TEST_RUN_PIPE")
8080
SYMLINK_PATH = None
8181
INCLUDE_BRANCHES = False
@@ -175,7 +175,7 @@ def pytest_exception_interact(node, call, report):
175175
report_value = "failure"
176176
node_id = get_absolute_test_id(node.nodeid, get_node_path(node))
177177
if node_id not in collected_tests_so_far:
178-
collected_tests_so_far.append(node_id)
178+
collected_tests_so_far.add(node_id)
179179
item_result = create_test_outcome(
180180
node_id,
181181
report_value,
@@ -300,7 +300,7 @@ def pytest_report_teststatus(report, config): # noqa: ARG001
300300
# Calculate the absolute test id and use this as the ID moving forward.
301301
absolute_node_id = get_absolute_test_id(report.nodeid, node_path)
302302
if absolute_node_id not in collected_tests_so_far:
303-
collected_tests_so_far.append(absolute_node_id)
303+
collected_tests_so_far.add(absolute_node_id)
304304
item_result = create_test_outcome(
305305
absolute_node_id,
306306
report_value,
@@ -334,7 +334,7 @@ def pytest_runtest_protocol(item, nextitem): # noqa: ARG001
334334
report_value = "skipped"
335335
cwd = pathlib.Path.cwd()
336336
if absolute_node_id not in collected_tests_so_far:
337-
collected_tests_so_far.append(absolute_node_id)
337+
collected_tests_so_far.add(absolute_node_id)
338338
item_result = create_test_outcome(
339339
absolute_node_id,
340340
report_value,

0 commit comments

Comments
 (0)