|
22 | 22 | get_current_task,
|
23 | 23 | move_on_after,
|
24 | 24 | sleep,
|
| 25 | + sleep_forever, |
25 | 26 | wait_all_tasks_blocked,
|
26 | 27 | )
|
27 | 28 | from anyio.abc import TaskGroup, TaskStatus
|
@@ -127,7 +128,6 @@ async def test_no_called_started_twice() -> None:
|
127 | 128 | async def taskfunc(*, task_status: TaskStatus) -> None:
|
128 | 129 | task_status.started()
|
129 | 130 |
|
130 |
| - # anyio>4.3.0 should not raise "RuntimeError: called 'started' twice on the same task status" |
131 | 131 | async with create_task_group() as tg:
|
132 | 132 | coro = tg.start(taskfunc)
|
133 | 133 | tg.cancel_scope.cancel()
|
@@ -196,9 +196,6 @@ async def taskfunc(*, task_status: TaskStatus) -> None:
|
196 | 196 | assert not finished
|
197 | 197 |
|
198 | 198 |
|
199 |
| -@pytest.mark.xfail( |
200 |
| - sys.version_info < (3, 9), reason="Requires a way to detect cancellation source" |
201 |
| -) |
202 | 199 | @pytest.mark.parametrize("anyio_backend", ["asyncio"])
|
203 | 200 | async def test_start_native_host_cancelled() -> None:
|
204 | 201 | started = finished = False
|
@@ -1347,6 +1344,24 @@ async def wait_cancel() -> None:
|
1347 | 1344 | await cancelled.wait()
|
1348 | 1345 |
|
1349 | 1346 |
|
| 1347 | +async def test_start_cancels_parent_scope() -> None: |
| 1348 | + """Regression test for #685 / #710.""" |
| 1349 | + started: bool = False |
| 1350 | + |
| 1351 | + async def in_task_group(task_status: TaskStatus[None]) -> None: |
| 1352 | + nonlocal started |
| 1353 | + started = True |
| 1354 | + await sleep_forever() |
| 1355 | + |
| 1356 | + async with create_task_group() as tg: |
| 1357 | + with CancelScope() as inner_scope: |
| 1358 | + inner_scope.cancel() |
| 1359 | + await tg.start(in_task_group) |
| 1360 | + |
| 1361 | + assert started |
| 1362 | + assert not tg.cancel_scope.cancel_called |
| 1363 | + |
| 1364 | + |
1350 | 1365 | class TestTaskStatusTyping:
|
1351 | 1366 | """
|
1352 | 1367 | These tests do not do anything at run time, but since the test suite is also checked
|
|
0 commit comments