Coverage for tests / test_tutorial / test_dependencies / test_tutorial010.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-04-06 01:24 +0000

1from typing import Annotated, Any 1efgh

2from unittest.mock import Mock, patch 1efgh

3 

4from fastapi import Depends, FastAPI 1efgh

5from fastapi.testclient import TestClient 1efgh

6 

7from docs_src.dependencies.tutorial010_py310 import get_db 1efgh

8 

9 

10def test_get_db(): 1efgh

11 app = FastAPI() 1abcd

12 

13 @app.get("/") 1abcd

14 def read_root(c: Annotated[Any, Depends(get_db)]): 1abcd

15 return {"c": str(c)} 1abcd

16 

17 client = TestClient(app) 1abcd

18 

19 dbsession_mock = Mock() 1abcd

20 

21 with patch( 1abcd

22 "docs_src.dependencies.tutorial010_py310.DBSession", 

23 return_value=dbsession_mock, 

24 create=True, 

25 ): 

26 response = client.get("/") 1abcd

27 

28 assert response.status_code == 200 1abcd

29 assert response.json() == {"c": str(dbsession_mock)} 1abcd