Skip to content

Commit dca74b8

Browse files
committed
move caching to a new function that wraps AST parsing
1 parent 46592c0 commit dca74b8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/pytest_run_parallel/plugin.py

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

177177
if n_workers > 1:
178178
thread_unsafe, thread_unsafe_reason = identify_thread_unsafe_nodes(

src/pytest_run_parallel/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,16 @@ def visit_Assign(self, node):
118118

119119

120120
@functools.lru_cache
121+
def ast_parse(fn):
122+
src = inspect.getsource(fn)
123+
return ast.parse(dedent(src))
124+
125+
121126
def identify_thread_unsafe_nodes(fn, skip_set, level=0):
122127
if is_hypothesis_test(fn):
123128
return True, "uses hypothesis"
124129
try:
125-
src = inspect.getsource(fn)
126-
tree = ast.parse(dedent(src))
130+
tree = ast_parse(fn)
127131
except Exception:
128132
return False, None
129133
visitor = ThreadUnsafeNodeVisitor(fn, skip_set, level=level)

0 commit comments

Comments
 (0)