Skip to content

Commit 79d759c

Browse files
committed
Detect unsafe calls that occur under assigments
1 parent ffc4139 commit 79d759c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/pytest_run_parallel/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def visit_Assign(self, node):
111111
f"calls thread-unsafe function: f{name_node} "
112112
"(inferred via func.__thread_safe__ == False)"
113113
)
114+
else:
115+
self.generic_visit(node)
114116

115117

116118
def identify_thread_unsafe_nodes(fn, skip_set, level=0):

tests/test_run_parallel.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,3 +1054,20 @@ def test_parallel_2(num_parallel_threads):
10541054
"*All tests were run in parallel! 🎉*",
10551055
]
10561056
)
1057+
1058+
1059+
def test_recurse_assign(pytester):
1060+
pytester.makepyfile("""
1061+
import pytest
1062+
1063+
def test_function_recurse_on_assign(num_parallel_threads):
1064+
w = pytest.warns(UserWarning)
1065+
assert num_parallel_threads == 1
1066+
""")
1067+
1068+
result = pytester.runpytest("--parallel-threads=10", "-v")
1069+
result.stdout.fnmatch_lines(
1070+
[
1071+
"*::test_function_recurse_on_assign PASSED*",
1072+
]
1073+
)

0 commit comments

Comments
 (0)