Skip to content

Commit 56353b1

Browse files
authored
gh-106458: Mark testthreadingmock.py with @requires_working_threading (GH-106366)
Mark `testthreadingmock.py` with `threading_helper.requires_working_threading`. Also add longer delays to reduce the change of a race conditions on the tests that validate short timeouts.
1 parent e7cd557 commit 56353b1

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Lib/test/test_unittest/testmock/testthreadingmock.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
import unittest
33
import concurrent.futures
44

5+
from test.support import threading_helper
56
from unittest.mock import patch, ThreadingMock, call
67

78

9+
threading_helper.requires_working_threading(module=True)
10+
11+
812
class Something:
913
def method_1(self):
1014
pass
@@ -133,11 +137,9 @@ def test_wait_failed_with_timeout_override(self):
133137

134138
with patch(f"{__name__}.Something", waitable_mock):
135139
something = Something()
136-
self.run_async(something.method_1, delay=0.1)
140+
self.run_async(something.method_1, delay=0.5)
137141
with self.assertRaises(AssertionError):
138142
something.method_1.wait_until_called(timeout=0.05)
139-
with self.assertRaises(AssertionError):
140-
something.method_1.wait_until_any_call_with(timeout=0.05)
141143

142144
def test_wait_success_called_before(self):
143145
waitable_mock = self._make_mock()
@@ -163,10 +165,10 @@ def test_wait_until_any_call_with_positional(self):
163165

164166
with patch(f"{__name__}.Something", waitable_mock):
165167
something = Something()
166-
self.run_async(something.method_1, 1, delay=0.1)
167-
self.run_async(something.method_1, 2, delay=0.2)
168-
self.run_async(something.method_1, 3, delay=0.3)
168+
self.run_async(something.method_1, 1, delay=0.2)
169169
self.assertNotIn(call(1), something.method_1.mock_calls)
170+
self.run_async(something.method_1, 2, delay=0.5)
171+
self.run_async(something.method_1, 3, delay=0.6)
170172

171173
something.method_1.wait_until_any_call_with(1)
172174
something.method_1.assert_called_with(1)
@@ -182,10 +184,10 @@ def test_wait_until_any_call_with_keywords(self):
182184

183185
with patch(f"{__name__}.Something", waitable_mock):
184186
something = Something()
185-
self.run_async(something.method_1, a=1, delay=0.1)
186-
self.run_async(something.method_1, b=2, delay=0.2)
187-
self.run_async(something.method_1, c=3, delay=0.3)
187+
self.run_async(something.method_1, a=1, delay=0.2)
188188
self.assertNotIn(call(a=1), something.method_1.mock_calls)
189+
self.run_async(something.method_1, b=2, delay=0.5)
190+
self.run_async(something.method_1, c=3, delay=0.6)
189191

190192
something.method_1.wait_until_any_call_with(a=1)
191193
something.method_1.assert_called_with(a=1)

0 commit comments

Comments
 (0)