mirror of https://github.com/tiangolo/fastapi.git
📝 Fix async test example not to trigger DeprecationWarning (#12084)
This commit is contained in:
parent
17a29149e4
commit
6e98249c21
|
|
@ -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.
|
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!}
|
{!../../../docs_src/async_tests/test_main.py!}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ $ pytest
|
||||||
|
|
||||||
⤴️ 👥 💪 ✍ `AsyncClient` ⏮️ 📱, & 📨 🔁 📨 ⚫️, ⚙️ `await`.
|
⤴️ 👥 💪 ✍ `AsyncClient` ⏮️ 📱, & 📨 🔁 📨 ⚫️, ⚙️ `await`.
|
||||||
|
|
||||||
```Python hl_lines="9-10"
|
```Python hl_lines="9-12"
|
||||||
{!../../../docs_src/async_tests/test_main.py!}
|
{!../../../docs_src/async_tests/test_main.py!}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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`.
|
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!}
|
{!../../../docs_src/async_tests/test_main.py!}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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`.
|
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!}
|
{!../../../docs_src/async_tests/test_main.py!}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,14 @@
|
||||||
import pytest
|
import pytest
|
||||||
from httpx import AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
from .main import app
|
from .main import app
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.anyio
|
@pytest.mark.anyio
|
||||||
async def test_root():
|
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("/")
|
response = await ac.get("/")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"message": "Tomato"}
|
assert response.json() == {"message": "Tomato"}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue