Search Options

Display Count
Sort
Preferred Language
Advanced Search

Results 1 - 10 of 70 for Lifespan (0.06 seconds)

  1. docs/zh-hant/docs/advanced/testing-events.md

    # 測試事件:lifespan 與 startup - shutdown { #testing-events-lifespan-and-startup-shutdown }
    
    當你需要在測試中執行 lifespan(生命週期)時,你可以使用 TestClient 並搭配 with 陳述式:
    
    {* ../../docs_src/app_testing/tutorial004_py310.py hl[9:15,18,27:28,30:32,41:43] *}
    
    你可以閱讀更多細節:[在測試中執行 lifespan](https://www.starlette.dev/lifespan/#running-lifespan-in-tests)(Starlette 官方文件)。
    
    對於已棄用的 `startup` 和 `shutdown` 事件,你可以這樣使用 TestClient:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sat Feb 14 08:15:26 GMT 2026
    - 618 bytes
    - Click Count (0)
  2. docs/en/docs/advanced/testing-events.md

    # Testing Events: lifespan and startup - shutdown { #testing-events-lifespan-and-startup-shutdown }
    
    When you need `lifespan` to run in your tests, you can use the `TestClient` with a `with` statement:
    
    {* ../../docs_src/app_testing/tutorial004_py310.py hl[9:15,18,27:28,30:32,41:43] *}
    
    
    You can read more details about the ["Running lifespan in tests in the official Starlette documentation site."](https://www.starlette.dev/lifespan/#running-lifespan-in-tests)
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 628 bytes
    - Click Count (0)
  3. docs/zh/docs/advanced/testing-events.md

    # 测试事件:lifespan 和 startup - shutdown { #testing-events-lifespan-and-startup-shutdown }
    
    当你需要在测试中运行 `lifespan` 时,可以将 `TestClient` 与 `with` 语句一起使用:
    
    {* ../../docs_src/app_testing/tutorial004_py310.py hl[9:15,18,27:28,30:32,41:43] *}
    
    你可以在[官方 Starlette 文档站点的“在测试中运行 lifespan”](https://www.starlette.dev/lifespan/#running-lifespan-in-tests)阅读更多细节。
    
    对于已弃用的 `startup` 和 `shutdown` 事件,可以按如下方式使用 `TestClient`:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Feb 13 13:37:57 GMT 2026
    - 622 bytes
    - Click Count (0)
  4. docs_src/app_testing/tutorial004_py310.py

    
    @asynccontextmanager
    async def lifespan(app: FastAPI):
        items["foo"] = {"name": "Fighters"}
        items["bar"] = {"name": "Tenders"}
        yield
        # clean up items
        items.clear()
    
    
    app = FastAPI(lifespan=lifespan)
    
    
    @app.get("/items/{item_id}")
    async def read_items(item_id: str):
        return items[item_id]
    
    
    def test_read_items():
        # Before the lifespan starts, "items" is still empty
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 1.2K bytes
    - Click Count (0)
  5. tests/test_router_events.py

        sub_router = APIRouter(lifespan=sub_router_lifespan)
        router = APIRouter(lifespan=router_lifespan)
        app = FastAPI(lifespan=lifespan)
        router.include_router(sub_router)
        app.include_router(router)
    
        with TestClient(app) as client:
            assert client.app_state == {"router": True}
    
    
    @pytest.mark.filterwarnings(
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Tue Feb 17 09:59:14 GMT 2026
    - 11.7K bytes
    - Click Count (0)
  6. docs/en/docs/advanced/events.md

    Including how to handle lifespan state that can be used in other areas of your code.
    
    ///
    
    ## Sub Applications { #sub-applications }
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 7.8K bytes
    - Click Count (0)
  7. docs/ja/docs/advanced/testing-events.md

    # イベントのテスト: lifespan と startup - shutdown { #testing-events-lifespan-and-startup-shutdown }
    
    テストで `lifespan` を実行する必要がある場合は、`with` 文と併用して `TestClient` を使用できます:
    
    {* ../../docs_src/app_testing/tutorial004_py310.py hl[9:15,18,27:28,30:32,41:43] *}
    
    より詳しい内容は、[公式 Starlette ドキュメントの「テストでの lifespan の実行」](https://www.starlette.dev/lifespan/#running-lifespan-in-tests) を参照してください。
    
    非推奨の `startup` および `shutdown` イベントについては、次のように `TestClient` を使用できます:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Fri Feb 13 15:24:30 GMT 2026
    - 724 bytes
    - Click Count (0)
  8. docs/ko/docs/advanced/testing-events.md

    # 이벤트 테스트: 라이프스팬 및 시작 - 종료 { #testing-events-lifespan-and-startup-shutdown }
    
    테스트에서 `lifespan`을 실행해야 하는 경우, `with` 문과 함께 `TestClient`를 사용할 수 있습니다:
    
    {* ../../docs_src/app_testing/tutorial004_py310.py hl[9:15,18,27:28,30:32,41:43] *}
    
    
    ["공식 Starlette 문서 사이트에서 테스트에서 라이프스팬 실행하기."](https://www.starlette.dev/lifespan/#running-lifespan-in-tests)에 대한 자세한 내용을 더 읽을 수 있습니다.
    
    더 이상 권장되지 않는 `startup` 및 `shutdown` 이벤트의 경우, 다음과 같이 `TestClient`를 사용할 수 있습니다:
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Sat Feb 14 08:57:01 GMT 2026
    - 741 bytes
    - Click Count (0)
  9. docs_src/events/tutorial003_py310.py

        return x * 42
    
    
    ml_models = {}
    
    
    @asynccontextmanager
    async def lifespan(app: FastAPI):
        # Load the ML model
        ml_models["answer_to_everything"] = fake_answer_to_everything_ml_model
        yield
        # Clean up the ML models and release the resources
        ml_models.clear()
    
    
    app = FastAPI(lifespan=lifespan)
    
    
    @app.get("/predict")
    async def predict(x: float):
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Feb 12 13:19:43 GMT 2026
    - 569 bytes
    - Click Count (0)
  10. docs/en/docs/advanced/async-tests.md

    ///
    
    /// warning
    
    If your application relies on lifespan events, the `AsyncClient` won't trigger these events. To ensure they are triggered, use `LifespanManager` from [florimondmanca/asgi-lifespan](https://github.com/florimondmanca/asgi-lifespan#usage).
    
    ///
    
    ## Other Asynchronous Function Calls { #other-asynchronous-function-calls }
    
    Created: Sun Apr 05 07:19:11 GMT 2026
    - Last Modified: Thu Mar 05 18:13:19 GMT 2026
    - 3.8K bytes
    - Click Count (0)
Back to Top