diff --git a/docs/en/docs/advanced/async-tests.md b/docs/en/docs/advanced/async-tests.md index 108bdf5c6..a44449f18 100644 --- a/docs/en/docs/advanced/async-tests.md +++ b/docs/en/docs/advanced/async-tests.md @@ -59,13 +59,13 @@ $ pytest ## In Detail -The lifespan function demonstrates how to manage the lifecycle of application-wide resources. During the app's lifespan, we open a resource (`some_state_open`) at startup and clean it up (`some_state_close`) during shutdown. +The lifespan function demonstrates how to manage the lifecycle of application-wide resources. During the app's lifespan, we open a resource (`some_state_open`) at startup and clean it up (`some_state_close`) during shutdown. We use **ASGITransport** from **HTTPX** to interact directly with the **FastAPI** app in an async test environment. -When testing **FastAPI** apps with a custom lifespan, it's critical to manually trigger it in the test context to ensure proper setup and teardown of resources. +When testing **FastAPI** apps with a custom lifespan, it's critical to manually trigger it in the test context to ensure proper setup and teardown of resources. -If you observe issues with state initialization or teardown in your tests, ensure that the lifespan is correctly invoked, and verify the app's state before and after requests. +If you observe issues with state initialization or teardown in your tests, ensure that the lifespan is correctly invoked, and verify the app's state before and after requests. ## Other Asynchronous Function Calls @@ -87,4 +87,3 @@ def event_loop() -> Generator[AbstractEventLoop, None, None]: ``` /// - diff --git a/docs_src/async_tests/test_main.py b/docs_src/async_tests/test_main.py index 5815d9dd3..8aea2fd6a 100644 --- a/docs_src/async_tests/test_main.py +++ b/docs_src/async_tests/test_main.py @@ -6,7 +6,9 @@ from .main import app, lifespan @pytest.mark.anyio async def test_root(): - async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client: + async with AsyncClient( + transport=ASGITransport(app=app), base_url="http://test" + ) as client: async with lifespan(app=app): # Send a GET request to the root endpoint response = await client.get("/")