Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
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.py Traceback (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 95507This 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
Linked PRs
- gh-142651: Make call_count of Mock thread safe #142656
- gh-142651 demonstrate that the test fails on main #142674
- [3.14] gh-142651: make
Mock.call_countthread-safe (GH-142656) #142743 - [3.13] gh-142651: make
Mock.call_countthread-safe (GH-142656) #142744 - gh-142651: use
NonCallableMock._lockfor thread safety of call_count #142922
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error