From cfcd3e594786e44fc06926c77055a4ee79f4d11b Mon Sep 17 00:00:00 2001 From: Yurii Motov Date: Thu, 18 Dec 2025 14:41:12 +0100 Subject: [PATCH] Fix coverage for `docs_src.debugging.tutorial001` --- .../test_tutorial/test_debugging/test_tutorial001.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_tutorial/test_debugging/test_tutorial001.py b/tests/test_tutorial/test_debugging/test_tutorial001.py index 5cfb78fce..aa774c54c 100644 --- a/tests/test_tutorial/test_debugging/test_tutorial001.py +++ b/tests/test_tutorial/test_debugging/test_tutorial001.py @@ -1,4 +1,5 @@ import importlib +import runpy import sys import unittest @@ -29,6 +30,17 @@ def test_get_root(client: TestClient): 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