Skip to content

Commit b20a605

Browse files
it works now
1 parent eac05aa commit b20a605

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

Lib/asyncio/tasks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,10 @@ def _leave_task(loop, task):
10551055
raise RuntimeError(f"Leaving task {task!r} does not match "
10561056
f"the current task {loop._current_task!r}.")
10571057
except AttributeError:
1058-
pass
1059-
loop._current_task = None
1058+
raise RuntimeError(f"Leaving task {task!r} does not match "
1059+
f"the current task.")
1060+
else:
1061+
loop._current_task = None
10601062

10611063

10621064
def _swap_current_task(loop, task):

Lib/test/test_asyncio/test_tasks.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,7 +3002,9 @@ def done(self):
30023002

30033003
def test__enter_task(self):
30043004
task = mock.Mock()
3005-
loop = mock.Mock()
3005+
class LoopLike:
3006+
pass
3007+
loop = LoopLike()
30063008
self.assertIsNone(asyncio.current_task(loop))
30073009
self._enter_task(loop, task)
30083010
self.assertIs(asyncio.current_task(loop), task)
@@ -3011,7 +3013,9 @@ def test__enter_task(self):
30113013
def test__enter_task_failure(self):
30123014
task1 = mock.Mock()
30133015
task2 = mock.Mock()
3014-
loop = mock.Mock()
3016+
class LoopLike:
3017+
pass
3018+
loop = LoopLike()
30153019
self._enter_task(loop, task1)
30163020
with self.assertRaises(RuntimeError):
30173021
self._enter_task(loop, task2)
@@ -3021,14 +3025,20 @@ def test__enter_task_failure(self):
30213025
def test__leave_task(self):
30223026
task = mock.Mock()
30233027
loop = mock.Mock()
3028+
class LoopLike:
3029+
pass
3030+
loop = LoopLike()
30243031
self._enter_task(loop, task)
30253032
self._leave_task(loop, task)
30263033
self.assertIsNone(asyncio.current_task(loop))
30273034

30283035
def test__leave_task_failure1(self):
30293036
task1 = mock.Mock()
30303037
task2 = mock.Mock()
3031-
loop = mock.Mock()
3038+
3039+
class LoopLike:
3040+
pass
3041+
loop = LoopLike()
30323042
self._enter_task(loop, task1)
30333043
with self.assertRaises(RuntimeError):
30343044
self._leave_task(loop, task2)
@@ -3037,7 +3047,10 @@ def test__leave_task_failure1(self):
30373047

30383048
def test__leave_task_failure2(self):
30393049
task = mock.Mock()
3040-
loop = mock.Mock()
3050+
3051+
class LoopLike:
3052+
pass
3053+
loop = LoopLike()
30413054
with self.assertRaises(RuntimeError):
30423055
self._leave_task(loop, task)
30433056
self.assertIsNone(asyncio.current_task(loop))

0 commit comments

Comments
 (0)