Skip to content

Commit 214f68f

Browse files
committed
use a try/except instead
1 parent 3013dbe commit 214f68f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/pytest_run_parallel/plugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +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
176-
skipped_functions)
175+
skipped_functions = {(".".join(x[:-1]), x[-1]) for x in skipped_functions}
177176

178177
if n_workers > 1:
179178
thread_unsafe, thread_unsafe_reason = identify_thread_unsafe_nodes(

src/pytest_run_parallel/utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ def visit_Assign(self, node):
117117
self.generic_visit(node)
118118

119119

120-
@functools.lru_cache
121-
def identify_thread_unsafe_nodes(fn, skip_set, level=0):
120+
def _identify_thread_unsafe_nodes(fn, skip_set, level=0):
122121
if is_hypothesis_test(fn):
123122
return True, "uses hypothesis"
124123
try:
@@ -131,6 +130,17 @@ def identify_thread_unsafe_nodes(fn, skip_set, level=0):
131130
return visitor.thread_unsafe, visitor.thread_unsafe_reason
132131

133132

133+
cached_thread_unsafe_identify = functools.lru_cache(_identify_thread_unsafe_nodes)
134+
135+
136+
def identify_thread_unsafe_nodes(fn, skip_set, level=0):
137+
try:
138+
return cached_thread_unsafe_identify(fn, skip_set, level=level)
139+
except TypeError:
140+
# skip caching if we hit an error about fn not being hashable
141+
return _identify_thread_unsafe_nodes(fn, skip_set, level=level)
142+
143+
134144
class ThreadComparator:
135145
def __init__(self, n_threads):
136146
self._barrier = threading.Barrier(n_threads)

0 commit comments

Comments
 (0)