test_tutorial001.py — fastapi Source File
Architecture documentation for test_tutorial001.py, a python file in the fastapi codebase. 7 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 03bf4966_0b63_ba47_3315_0b938c7f27fa["test_tutorial001.py"] 83e01a9c_50a9_bec9_6f86_8e729106de01["importlib"] 03bf4966_0b63_ba47_3315_0b938c7f27fa --> 83e01a9c_50a9_bec9_6f86_8e729106de01 238ca8dc_67ac_a93a_ec78_fc27ec421619["runpy"] 03bf4966_0b63_ba47_3315_0b938c7f27fa --> 238ca8dc_67ac_a93a_ec78_fc27ec421619 65099b90_26c1_5db5_09e6_30dc0ea421e3["sys"] 03bf4966_0b63_ba47_3315_0b938c7f27fa --> 65099b90_26c1_5db5_09e6_30dc0ea421e3 709e9c92_e467_84d2_b273_ea6b76ef8198["unittest"] 03bf4966_0b63_ba47_3315_0b938c7f27fa --> 709e9c92_e467_84d2_b273_ea6b76ef8198 5befe8bf_65d1_d058_6b78_4a597a8488e9["pytest"] 03bf4966_0b63_ba47_3315_0b938c7f27fa --> 5befe8bf_65d1_d058_6b78_4a597a8488e9 a7c04dee_ee23_5891_b185_47ff6bed036d["testclient.py"] 03bf4966_0b63_ba47_3315_0b938c7f27fa --> a7c04dee_ee23_5891_b185_47ff6bed036d a7f4e7b0_9725_db90_5cbc_7ca8211b323a["inline_snapshot"] 03bf4966_0b63_ba47_3315_0b938c7f27fa --> a7f4e7b0_9725_db90_5cbc_7ca8211b323a style 03bf4966_0b63_ba47_3315_0b938c7f27fa fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import importlib
import runpy
import sys
import unittest
import pytest
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
MOD_NAME = "docs_src.debugging.tutorial001_py39"
@pytest.fixture(name="client")
def get_client():
mod = importlib.import_module(MOD_NAME)
client = TestClient(mod.app)
return client
def test_uvicorn_run_is_not_called_on_import():
if sys.modules.get(MOD_NAME):
del sys.modules[MOD_NAME] # pragma: no cover
with unittest.mock.patch("uvicorn.run") as uvicorn_run_mock:
importlib.import_module(MOD_NAME)
uvicorn_run_mock.assert_not_called()
def test_get_root(client: TestClient):
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"hello world": "ba"}
def test_uvicorn_run_called_when_run_as_main(): # Just for coverage
if sys.modules.get(MOD_NAME):
del sys.modules[MOD_NAME]
with unittest.mock.patch("uvicorn.run") as uvicorn_run_mock:
runpy.run_module(MOD_NAME, run_name="__main__")
uvicorn_run_mock.assert_called_once_with(
unittest.mock.ANY, host="0.0.0.0", port=8000
)
def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json")
assert response.status_code == 200
assert response.json() == snapshot(
{
"openapi": "3.1.0",
"info": {"title": "FastAPI", "version": "0.1.0"},
"paths": {
"/": {
"get": {
"summary": "Root",
"operationId": "root__get",
"responses": {
"200": {
"description": "Successful Response",
"content": {"application/json": {"schema": {}}},
},
},
}
}
},
}
)
Domain
Subdomains
Functions
Dependencies
- importlib
- inline_snapshot
- pytest
- runpy
- sys
- testclient.py
- unittest
Source
Frequently Asked Questions
What does test_tutorial001.py do?
test_tutorial001.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_tutorial001.py?
test_tutorial001.py defines 5 function(s): get_client, test_get_root, test_openapi_schema, test_uvicorn_run_called_when_run_as_main, test_uvicorn_run_is_not_called_on_import.
What does test_tutorial001.py depend on?
test_tutorial001.py imports 7 module(s): importlib, inline_snapshot, pytest, runpy, sys, testclient.py, unittest.
Where is test_tutorial001.py in the architecture?
test_tutorial001.py is located at tests/test_tutorial/test_debugging/test_tutorial001.py (domain: FastAPI, subdomain: Applications, directory: tests/test_tutorial/test_debugging).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free