Home / File/ test_tutorial008.py — fastapi Source File

test_tutorial008.py — fastapi Source File

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

File python FastAPI Applications 8 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  006f9ea5_2d09_91c9_f69c_3b181f3aa010["test_tutorial008.py"]
  83e01a9c_50a9_bec9_6f86_8e729106de01["importlib"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010 --> 83e01a9c_50a9_bec9_6f86_8e729106de01
  65099b90_26c1_5db5_09e6_30dc0ea421e3["sys"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010 --> 65099b90_26c1_5db5_09e6_30dc0ea421e3
  fb2d9376_ca24_f2b2_f130_cc10e9f2e732["types"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010 --> fb2d9376_ca24_f2b2_f130_cc10e9f2e732
  0dda2280_3359_8460_301c_e98c77e78185["typing"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010 --> 0dda2280_3359_8460_301c_e98c77e78185
  d1bf66df_8a92_7a7c_dab4_0865060effa4["unittest.mock"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010 --> d1bf66df_8a92_7a7c_dab4_0865060effa4
  5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010 --> 5befe8bf_65d1_d058_6b78_4a597a8488e9
  534f6e44_61b8_3c38_8b89_6934a6df9802["__init__.py"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010 --> 534f6e44_61b8_3c38_8b89_6934a6df9802
  a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"]
  006f9ea5_2d09_91c9_f69c_3b181f3aa010 --> a7c04dee_ee23_5891_b185_47ff6bed036d
  style 006f9ea5_2d09_91c9_f69c_3b181f3aa010 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import importlib
import sys
from types import ModuleType
from typing import Annotated, Any
from unittest.mock import Mock, patch

import pytest
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient


@pytest.fixture(
    name="module",
    params=[
        "tutorial008_py39",
        pytest.param(
            "tutorial008_an_py39",
            marks=pytest.mark.xfail(
                sys.version_info < (3, 14),
                reason="Fails with `NameError: name 'DepA' is not defined`",
            ),
        ),
    ],
)
def get_module(request: pytest.FixtureRequest):
    mod_name = f"docs_src.dependencies.{request.param}"
    mod = importlib.import_module(mod_name)
    return mod


def test_get_db(module: ModuleType):
    app = FastAPI()

    @app.get("/")
    def read_root(c: Annotated[Any, Depends(module.dependency_c)]):
        return {"c": str(c)}

    client = TestClient(app)

    a_mock = Mock()
    b_mock = Mock()
    c_mock = Mock()

    with (
        patch(
            f"{module.__name__}.generate_dep_a",
            return_value=a_mock,
            create=True,
        ),
        patch(
            f"{module.__name__}.generate_dep_b",
            return_value=b_mock,
            create=True,
        ),
        patch(
            f"{module.__name__}.generate_dep_c",
            return_value=c_mock,
            create=True,
        ),
    ):
        response = client.get("/")

    assert response.status_code == 200
    assert response.json() == {"c": str(c_mock)}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does test_tutorial008.py do?
test_tutorial008.py is a source file in the fastapi codebase, written in python. It belongs to the FastAPI domain, Applications subdomain.
What functions are defined in test_tutorial008.py?
test_tutorial008.py defines 2 function(s): get_module, test_get_db.
What does test_tutorial008.py depend on?
test_tutorial008.py imports 8 module(s): __init__.py, importlib, pytest, sys, testclient.py, types, typing, unittest.mock.
Where is test_tutorial008.py in the architecture?
test_tutorial008.py is located at tests/test_tutorial/test_dependencies/test_tutorial008.py (domain: FastAPI, subdomain: Applications, directory: tests/test_tutorial/test_dependencies).

Analyze Your Own Codebase

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

Try Supermodel Free