Skip to content

Commit eef1a43

Browse files
Copiloteleanorjboyd
andcommitted
Optimize pytest duplicate check from O(n) to O(1) by using set instead of list
Co-authored-by: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com>
1 parent 7d7158c commit eef1a43

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
@@ -170,7 +170,7 @@ def pytest_exception_interact(node, call, report):
170170
report_value = "failure"
171171
node_id = get_absolute_test_id(node.nodeid, get_node_path(node))
172172
if node_id not in collected_tests_so_far:
173-
collected_tests_so_far.append(node_id)
173+
collected_tests_so_far.add(node_id)
174174
item_result = create_test_outcome(
175175
node_id,
176176
report_value,
@@ -295,7 +295,7 @@ def pytest_report_teststatus(report, config): # noqa: ARG001
295295
# Calculate the absolute test id and use this as the ID moving forward.
296296
absolute_node_id = get_absolute_test_id(report.nodeid, node_path)
297297
if absolute_node_id not in collected_tests_so_far:
298-
collected_tests_so_far.append(absolute_node_id)
298+
collected_tests_so_far.add(absolute_node_id)
299299
item_result = create_test_outcome(
300300
absolute_node_id,
301301
report_value,
@@ -329,7 +329,7 @@ def pytest_runtest_protocol(item, nextitem): # noqa: ARG001
329329
report_value = "skipped"
330330
cwd = pathlib.Path.cwd()
331331
if absolute_node_id not in collected_tests_so_far:
332-
collected_tests_so_far.append(absolute_node_id)
332+
collected_tests_so_far.add(absolute_node_id)
333333
item_result = create_test_outcome(
334334
absolute_node_id,
335335
report_value,

0 commit comments

Comments
 (0)