| 33 | |
| 34 | |
| 35 | def current_task() -> Task[Any] | trio.lowlevel.Task: |
| 36 | # anyio's TaskInfo comparisons are invalid after their associated native |
| 37 | # task object is GC'd https://github.com/agronholm/anyio/issues/324 |
| 38 | asynclib_name = sniffio.current_async_library() |
| 39 | if asynclib_name == "trio": |
| 40 | return trio.lowlevel.current_task() |
| 41 | |
| 42 | if asynclib_name == "asyncio": |
| 43 | task = asyncio_current_task() |
| 44 | if task is None: |
| 45 | raise RuntimeError("must be called from a running task") # pragma: no cover |
| 46 | return task |
| 47 | raise RuntimeError(f"unsupported asynclib={asynclib_name}") # pragma: no cover |
| 48 | |
| 49 | |
| 50 | def test_use_testclient_in_endpoint(test_client_factory: TestClientFactory) -> None: |