File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Lib/test/test_unittest/testmock Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 11import time
22import unittest
3+ import threading
34import concurrent .futures
45
56from test .support import threading_helper
@@ -196,6 +197,22 @@ def test_reset_mock_resets_wait(self):
196197 m .wait_until_any_call_with ()
197198 m .assert_called_once ()
198199
200+ def test_call_count_thread_safe (self ):
201+ m = ThreadingMock ()
202+ # 3k loops reliably reproduces the issue while keeping runtime ~0.6s
203+ LOOPS = 3_000
204+ THREADS = 10
205+ def test_function ():
206+ for _ in range (LOOPS ):
207+ m ()
208+ threads = [threading .Thread (target = test_function ) for _ in range (THREADS )]
209+ for thread in threads :
210+ thread .start ()
211+ for thread in threads :
212+ thread .join ()
213+
214+ self .assertEqual (m .call_count , LOOPS * THREADS )
215+
199216
200217if __name__ == "__main__" :
201218 unittest .main ()
You can’t perform that action at this time.
0 commit comments