Home / File/ test_router_events.py — fastapi Source File

test_router_events.py — fastapi Source File

Architecture documentation for test_router_events.py, a python file in the fastapi codebase. 7 imports, 0 dependents.

File python FastAPI Routing 7 imports 11 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  05561238_1d26_3221_b177_440da9d6e710["test_router_events.py"]
  07d79a2e_d4e9_0bbb_be90_936274444c8c["collections.abc"]
  05561238_1d26_3221_b177_440da9d6e710 --> 07d79a2e_d4e9_0bbb_be90_936274444c8c
  a88eb002_9197_73f3_410d_ee5315767f34["contextlib"]
  05561238_1d26_3221_b177_440da9d6e710 --> a88eb002_9197_73f3_410d_ee5315767f34
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  05561238_1d26_3221_b177_440da9d6e710 --> 0dda2280_3359_8460_301c_e98c77e78185
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  05561238_1d26_3221_b177_440da9d6e710 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  05561238_1d26_3221_b177_440da9d6e710 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  05561238_1d26_3221_b177_440da9d6e710 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  6913fbd4_39df_d14b_44bb_522e99b65b90["pydantic"]
  05561238_1d26_3221_b177_440da9d6e710 --> 6913fbd4_39df_d14b_44bb_522e99b65b90
  style 05561238_1d26_3221_b177_440da9d6e710 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from typing import Union

import pytest
from fastapi import APIRouter, FastAPI, Request
from fastapi.testclient import TestClient
from pydantic import BaseModel


class State(BaseModel):
    app_startup: bool = False
    app_shutdown: bool = False
    router_startup: bool = False
    router_shutdown: bool = False
    sub_router_startup: bool = False
    sub_router_shutdown: bool = False


@pytest.fixture
def state() -> State:
    return State()


@pytest.mark.filterwarnings(
    r"ignore:\s*on_event is deprecated, use lifespan event handlers instead.*:DeprecationWarning"
)
def test_router_events(state: State) -> None:
    app = FastAPI()

    @app.get("/")
    def main() -> dict[str, str]:
        return {"message": "Hello World"}

    @app.on_event("startup")
    def app_startup() -> None:
        state.app_startup = True

    @app.on_event("shutdown")
    def app_shutdown() -> None:
        state.app_shutdown = True

    router = APIRouter()

    @router.on_event("startup")
    def router_startup() -> None:
        state.router_startup = True

    @router.on_event("shutdown")
    def router_shutdown() -> None:
        state.router_shutdown = True

    sub_router = APIRouter()

    @sub_router.on_event("startup")
    def sub_router_startup() -> None:
        state.sub_router_startup = True

    @sub_router.on_event("shutdown")
    def sub_router_shutdown() -> None:
// ... (320 more lines)

Domain

Subdomains

Classes

Dependencies

Frequently Asked Questions

What does test_router_events.py do?
test_router_events.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Routing subdomain.
What functions are defined in test_router_events.py?
test_router_events.py defines 11 function(s): state, test_app_lifespan_state, test_merged_mixed_state_lifespans, test_merged_no_return_lifespans_return_none, test_router_async_generator_lifespan, test_router_async_shutdown_handler, test_router_events, test_router_nested_lifespan_state, test_router_nested_lifespan_state_overriding_by_parent, test_router_sync_generator_lifespan, and 1 more.
What does test_router_events.py depend on?
test_router_events.py imports 7 module(s): __init__.py, collections.abc, contextlib, pydantic, pytest, testclient.py, typing.
Where is test_router_events.py in the architecture?
test_router_events.py is located at tests/test_router_events.py (domain: FastAPI, subdomain: Routing, directory: tests).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free