Skip to content

Commit fbcdcbd

Browse files
test(utils): Expose that thread mocks break on other callers
1 parent 8a20ce4 commit fbcdcbd

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎tests/test_utils.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,17 +1182,27 @@ def target():
11821182

11831183
def get_current_thread_meta_patched(**patch_kwargs):
11841184
results = Queue(maxsize=1)
1185+
patched = threading.Event()
1186+
other_caller_done = threading.Event()
11851187

11861188
def target():
11871189
with mock.patch("threading.current_thread", **patch_kwargs):
1190+
patched.set()
1191+
other_caller_done.wait()
11881192
results.put(get_current_thread_meta())
11891193

11901194
thread = threading.Thread(target=target)
11911195
thread.start()
1196+
patched.wait()
1197+
try:
1198+
thread.join(0)
1199+
finally:
1200+
other_caller_done.set()
11921201
thread.join()
11931202
return results.get(timeout=1)
11941203

11951204

1205+
@pytest.mark.xfail(strict=True, raises=StopIteration)
11961206
def test_get_current_thread_meta_bad_running_thread():
11971207
main_thread = threading.main_thread()
11981208
assert (
@@ -1201,6 +1211,7 @@ def test_get_current_thread_meta_bad_running_thread():
12011211
) == get_current_thread_meta_patched(side_effect=["fake thread"])
12021212

12031213

1214+
@pytest.mark.xfail(strict=True, raises=StopIteration)
12041215
def test_get_current_thread_meta_main_thread():
12051216
main_thread = threading.main_thread()
12061217
# mock that somehow the current thread doesn't exist

0 commit comments

Comments
 (0)