Skip to content

Commit 3013dbe

Browse files
committed
use an lru_cache to speed up recursive ast parsing
1 parent 3d65bf7 commit 3013dbe

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/pytest_run_parallel/plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ def pytest_itemcollected(item):
172172
skipped_functions = [
173173
x.split(".") for x in item.config.getini("thread_unsafe_functions")
174174
]
175-
skipped_functions = {(".".join(x[:-1]), x[-1]) for x in skipped_functions}
175+
skipped_functions = frozenset((".".join(x[:-1]), x[-1]) for x in
176+
skipped_functions)
176177

177178
if n_workers > 1:
178179
thread_unsafe, thread_unsafe_reason = identify_thread_unsafe_nodes(

src/pytest_run_parallel/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ast
2+
import functools
23
import inspect
34
import threading
45
import types
@@ -116,6 +117,7 @@ def visit_Assign(self, node):
116117
self.generic_visit(node)
117118

118119

120+
@functools.lru_cache
119121
def identify_thread_unsafe_nodes(fn, skip_set, level=0):
120122
if is_hypothesis_test(fn):
121123
return True, "uses hypothesis"

0 commit comments

Comments
 (0)