Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Bug report
Bug description:
Running this test program with (plain old, non-free-threaded) Python 3.14 fails:
importthreadingimportunittest.mockm=unittest.mock.ThreadingMock()LOOPS=10_000THREADS=10deftest_function():for_inrange(LOOPS):m()threads= [threading.Thread(target=test_function)for_inrange(THREADS)]forthreadinthreads:thread.start()forthreadinthreads:thread.join()assertm.call_count==LOOPS*THREADS,f"Expected{LOOPS*THREADS}, got{m.call_count}"
Results are something like:
$ python3.14 python_mock_call_count_atomicity.pyTraceback (most recent call last): File"python_mock_call_count_atomicity.py", line 21,in<module> assert m.call_count == LOOPS* THREADS, f"Expected {LOOPS * THREADS}, got {m.call_count}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^AssertionError: Expected 100000, got 95507
This is essentially the same bug as#122957, but that was closed with just a fix to the test suite. This is a bug report that the version of MagicMock for multithreading tests is not thread-safe and so the obvious way of writing those multithreading tests may not work.
CPython versions tested on:
3.14
Operating systems tested on:
Linux