Browse Source

Returned the old description, corrected it to asyncio.Runner

pull/13163/head
oleg.korshunov 5 months ago
parent
commit
33a6afc5cb
  1. 15
      docs/en/docs/advanced/async-tests.md

15
docs/en/docs/advanced/async-tests.md

@ -77,13 +77,16 @@ As the testing function is now asynchronous, you can now also call (and await) o
If you encounter a `RuntimeError: Task attached to a different loop` when integrating asynchronous function calls in your tests, you can override the default pytest event loop using the following fixture: If you encounter a `RuntimeError: Task attached to a different loop` when integrating asynchronous function calls in your tests, you can override the default pytest event loop using the following fixture:
```python ```python
import asyncio
import pytest
from collections.abc import Generator
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def event_loop() -> Generator[AbstractEventLoop, None, None]: def event_loop() -> Generator[asyncio.AbstractEventLoop, None, None]:
"""Overrides pytest default function scoped event loop""" """Overrides pytest default function scoped event loop using asyncio.Runner"""
policy = asyncio.get_event_loop_policy() with asyncio.Runner() as runner:
loop = policy.new_event_loop() yield runner.get_loop()
yield loop
loop.close()
``` ```
/// ///

Loading…
Cancel
Save