📝 Fix async test example not to trigger DeprecationWarning (#12084)

This commit is contained in:
Marcin Sulikowski 2024-08-30 18:00:41 +02:00 committed by GitHub
parent 17a29149e4
commit 6e98249c21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 8 additions and 6 deletions

View File

@ -72,7 +72,7 @@ Beachten Sie, dass die Testfunktion jetzt `async def` ist und nicht nur `def` wi
Dann können wir einen `AsyncClient` mit der App erstellen und mit `await` asynchrone Requests an ihn senden.
```Python hl_lines="9-10"
```Python hl_lines="9-12"
{!../../../docs_src/async_tests/test_main.py!}
```

View File

@ -72,7 +72,7 @@ $ pytest
⤴️ 👥 💪 ✍ `AsyncClient` ⏮️ 📱, & 📨 🔁 📨 ⚫️, ⚙️ `await`.
```Python hl_lines="9-10"
```Python hl_lines="9-12"
{!../../../docs_src/async_tests/test_main.py!}
```

View File

@ -72,7 +72,7 @@ Note that the test function is now `async def` instead of just `def` as before w
Then we can create an `AsyncClient` with the app, and send async requests to it, using `await`.
```Python hl_lines="9-10"
```Python hl_lines="9-12"
{!../../../docs_src/async_tests/test_main.py!}
```

View File

@ -72,7 +72,7 @@ Note que a função de teste é `async def` agora, no lugar de apenas `def` como
Então podemos criar um `AsyncClient` com a aplicação, e enviar requisições assíncronas para ela utilizando `await`.
```Python hl_lines="9-10"
```Python hl_lines="9-12"
{!../../../docs_src/async_tests/test_main.py!}
```

View File

@ -1,12 +1,14 @@
import pytest
from httpx import AsyncClient
from httpx import ASGITransport, AsyncClient
from .main import app
@pytest.mark.anyio
async def test_root():
async with AsyncClient(app=app, base_url="http://test") as ac:
async with AsyncClient(
transport=ASGITransport(app=app), base_url="http://test"
) as ac:
response = await ac.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Tomato"}