Skip to content

Commit 4e14182

Browse files
fix tests
1 parent 19e3bfa commit 4e14182

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Lib/test/test_asyncio/test_events.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,11 +2930,16 @@ class GetEventLoopTestsMixin:
29302930
get_running_loop_impl = None
29312931
get_event_loop_impl = None
29322932

2933+
Task = None
2934+
Future = None
2935+
29332936
def setUp(self):
29342937
self._get_running_loop_saved = events._get_running_loop
29352938
self._set_running_loop_saved = events._set_running_loop
29362939
self.get_running_loop_saved = events.get_running_loop
29372940
self.get_event_loop_saved = events.get_event_loop
2941+
self._Task_saved = asyncio.Task
2942+
self._Future_saved = asyncio.Future
29382943

29392944
events._get_running_loop = type(self)._get_running_loop_impl
29402945
events._set_running_loop = type(self)._set_running_loop_impl
@@ -2946,6 +2951,8 @@ def setUp(self):
29462951
asyncio.get_running_loop = type(self).get_running_loop_impl
29472952
asyncio.get_event_loop = type(self).get_event_loop_impl
29482953

2954+
asyncio.Task = asyncio.tasks.Task = type(self).Task
2955+
asyncio.Future = asyncio.futures.Future = type(self).Future
29492956
super().setUp()
29502957

29512958
self.loop = asyncio.new_event_loop()
@@ -2968,8 +2975,10 @@ def tearDown(self):
29682975
asyncio.get_running_loop = self.get_running_loop_saved
29692976
asyncio.get_event_loop = self.get_event_loop_saved
29702977

2978+
asyncio.Task = asyncio.tasks.Task = self._Task_saved
2979+
asyncio.Future = asyncio.futures.Future = self._Future_saved
2980+
29712981
if sys.platform != 'win32':
2972-
@unittest.skip("skip")
29732982
def test_get_event_loop_new_process(self):
29742983
# bpo-32126: The multiprocessing module used by
29752984
# ProcessPoolExecutor is not functional when the
@@ -2995,7 +3004,6 @@ async def main():
29953004
self.loop.run_until_complete(main()),
29963005
'hello')
29973006

2998-
@unittest.skip("skip")
29993007
def test_get_event_loop_returns_running_loop(self):
30003008
class TestError(Exception):
30013009
pass
@@ -3043,7 +3051,6 @@ async def func():
30433051

30443052
self.assertIs(asyncio._get_running_loop(), None)
30453053

3046-
@unittest.skip("skip")
30473054
def test_get_event_loop_returns_running_loop2(self):
30483055
old_policy = asyncio._get_event_loop_policy()
30493056
try:
@@ -3090,6 +3097,8 @@ class TestPyGetEventLoop(GetEventLoopTestsMixin, unittest.TestCase):
30903097
get_running_loop_impl = events._py_get_running_loop
30913098
get_event_loop_impl = events._py_get_event_loop
30923099

3100+
Task = asyncio.tasks._PyTask
3101+
Future = asyncio.futures._PyFuture
30933102

30943103
try:
30953104
import _asyncio # NoQA
@@ -3104,6 +3113,8 @@ class TestCGetEventLoop(GetEventLoopTestsMixin, unittest.TestCase):
31043113
get_running_loop_impl = events._c_get_running_loop
31053114
get_event_loop_impl = events._c_get_event_loop
31063115

3116+
Task = asyncio.tasks._CTask
3117+
Future = asyncio.futures._CFuture
31073118

31083119
class TestServer(unittest.TestCase):
31093120

Lib/test/test_asyncio/test_tasks.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2252,7 +2252,7 @@ def test_wait_invalid_args(self):
22522252
# wait() expects at least a future
22532253
self.assertRaises(ValueError, self.loop.run_until_complete,
22542254
asyncio.wait([]))
2255-
@unittest.skip("This test is flaky")
2255+
22562256
def test_log_destroyed_pending_task(self):
22572257

22582258
async def kill_me(loop):
@@ -3012,6 +3012,9 @@ def done(self):
30123012
def test__enter_task(self):
30133013
task = mock.Mock()
30143014
loop = mock.Mock()
3015+
# _enter_task is called by Task.__step while the loop
3016+
# is running, so set the loop as the running loop
3017+
# for a more realistic test.
30153018
asyncio._set_running_loop(loop)
30163019
self.assertIsNone(self.current_task(loop))
30173020
self._enter_task(loop, task)
@@ -3044,6 +3047,9 @@ def test__leave_task_failure1(self):
30443047
task1 = mock.Mock()
30453048
task2 = mock.Mock()
30463049
loop = mock.Mock()
3050+
# _leave_task is called by Task.__step while the loop
3051+
# is running, so set the loop as the running loop
3052+
# for a more realistic test.
30473053
asyncio._set_running_loop(loop)
30483054
self._enter_task(loop, task1)
30493055
with self.assertRaises(RuntimeError):

0 commit comments

Comments
 (0)