gh-142651: make `Mock.call_count` thread-safe (#142656) · python/cpython@850f95f · GitHub
Skip to content

Commit 850f95f

Browse files
authored
gh-142651: make Mock.call_count thread-safe (#142656)
1 parent 38ad651 commit 850f95f

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

Lib/test/test_unittest/testmock/testthreadingmock.py

Lines changed: 23 additions & 1 deletion

Lib/unittest/mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,14 +1180,14 @@ def _mock_call(self, /, *args, **kwargs):
11801180

11811181
def _increment_mock_call(self, /, *args, **kwargs):
11821182
self.called = True
1183-
self.call_count += 1
11841183

11851184
# handle call_args
11861185
# needs to be set here so assertions on call arguments pass before
11871186
# execution in the case of awaited calls
11881187
_call = _Call((args, kwargs), two=True)
11891188
self.call_args = _call
11901189
self.call_args_list.append(_call)
1190+
self.call_count = len(self.call_args_list)
11911191

11921192
# initial stuff for method_calls:
11931193
do_method_calls = self._mock_parent is not None
Lines changed: 3 additions & 0 deletions

0 commit comments

Comments
 (0)