Skip to content

Commit 816a404

Browse files
committed
format file and add funcopy call_count
1 parent fe7be86 commit 816a404

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Lib/test/test_unittest/testmock/testthreadingmock.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,23 @@ def test_reset_mock_resets_wait(self):
198198
m.assert_called_once()
199199

200200
def test_call_count_thread_safe(self):
201-
201+
202202
m = ThreadingMock()
203-
203+
204204
# 3k loops reliably reproduces the issue while keeping runtime ~0.6s
205205
LOOPS = 3_000
206206
THREADS = 10
207-
207+
208208
def test_function():
209209
for _ in range(LOOPS):
210210
m()
211-
211+
212212
threads = [threading.Thread(target=test_function) for _ in range(THREADS)]
213213
for thread in threads:
214214
thread.start()
215215
for thread in threads:
216216
thread.join()
217-
217+
218218
self.assertEqual(m.call_count, LOOPS * THREADS,
219219
f"Expected {LOOPS * THREADS}, got {m.call_count}")
220220

Lib/unittest/mock.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def reset_mock():
256256
ret.reset_mock()
257257

258258
funcopy.called = False
259+
funcopy.call_count = property(lambda self: len(funcopy.call_args_list))
259260
funcopy.call_args = None
260261
funcopy.call_args_list = _CallList()
261262
funcopy.method_calls = _CallList()

0 commit comments

Comments
 (0)