]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.14] gh-150175: Fix ThreadingMock call_count race condition (GH-150176) (#150181)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 26 May 2026 19:46:42 +0000 (21:46 +0200)
committerGitHub <noreply@github.com>
Tue, 26 May 2026 19:46:42 +0000 (12:46 -0700)
commit8053ead86b8ca5f97472366a3623c53ee3a15350
treee12d322682baae7835d9c8cd187b9eb913338524
parent8732053c92fdf3120e94ea2b8fc2d39b372f0602
[3.14] gh-150175: Fix ThreadingMock call_count race condition (GH-150176) (#150181)

gh-150175: Fix ThreadingMock call_count race condition (GH-150176)

ThreadingMock._increment_mock_call() was not thread-safe.
Multiple threads calling the mock simultaneously could lose
increments due to race conditions on call_count and other
attributes.

Fix by overriding _increment_mock_call in ThreadingMixin
and wrapping it with the existing _mock_calls_events_lock.
(cherry picked from commit 388e023fe1197c1ffed374520ed45df4ac72b8f5)

Co-authored-by: saisneha196 <156835592+saisneha196@users.noreply.github.com>
Lib/unittest/mock.py
Misc/NEWS.d/next/Library/2026-05-21-11-25-58.gh-issue-150175.8H4Caz.rst [new file with mode: 0644]