]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
📝 Fix async test example not to trigger DeprecationWarning (#12084)
authorMarcin Sulikowski <marcin.k.sulikowski@gmail.com>
Fri, 30 Aug 2024 16:00:41 +0000 (18:00 +0200)
committerGitHub <noreply@github.com>
Fri, 30 Aug 2024 16:00:41 +0000 (18:00 +0200)
docs/de/docs/advanced/async-tests.md
docs/em/docs/advanced/async-tests.md
docs/en/docs/advanced/async-tests.md
docs/pt/docs/advanced/async-tests.md
docs_src/async_tests/test_main.py

index 9f0bd4aa2e668e3a7d985003e14da44f24ffeb39..e56841faadf4dcc6f23415448230925f6a7d8290 100644 (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!}
 ```
 
index 324b4f68a5ffd06a3e7a44d0067b3945a09d4552..11f885fe608b9014612238023c3d6e8c1a8f6074 100644 (file)
@@ -72,7 +72,7 @@ $ pytest
 
 ⤴️ 👥 💪 ✍ `AsyncClient` ⏮️ 📱, &amp; 📨 🔁 📨 ⚫️, ⚙️ `await`.
 
-```Python hl_lines="9-10"
+```Python hl_lines="9-12"
 {!../../../docs_src/async_tests/test_main.py!}
 ```
 
index ac459ff0c80d387e79d091aabfa4a294e913db1a..580d9142c45743c67b593276fef914d19e88d68e 100644 (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!}
 ```
 
index ab5bfa6482a0d9ba9d311a7ae6b36bf48ba08023..7cac262627f212f5ecdc927b32b28177ffb34d14 100644 (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!}
 ```
 
index 9f1527d5f60285fa329fba3d2c436c1f56bdfb0e..a57a31f7d897a3c945841642ffb5ed98467c046f 100644 (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"}