Coverage for tests / test_tutorial / test_fastapi / test_app_testing / test_tutorial001_tests006.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-06-10 09:40 +0000

1import importlib 1abcdefgh

2 

3import pytest 1abcdefgh

4from fastapi.testclient import TestClient 1abcdefgh

5from sqlmodel import Session 1abcdefgh

6 

7from docs_src.tutorial.fastapi.app_testing.tutorial001_py310 import main as app_mod 1abcdefgh

8from docs_src.tutorial.fastapi.app_testing.tutorial001_py310 import ( 1abcdefgh

9 test_main_006 as test_mod, 

10) 

11from docs_src.tutorial.fastapi.app_testing.tutorial001_py310.test_main_006 import ( 1abcdefgh

12 client_fixture, 

13 session_fixture, 

14) 

15 

16assert session_fixture, "This keeps the session fixture used below" 1abcdefgh

17assert client_fixture, "This keeps the client fixture used below" 1abcdefgh

18 

19 

20@pytest.fixture(name="prepare") 1abcdefgh

21def prepare_fixture(clear_sqlmodel): 1abcdefgh

22 # Trigger side effects of registering table models in SQLModel 

23 # This has to be called after clear_sqlmodel, but before the session_fixture 

24 # That's why the extra custom fixture here 

25 importlib.reload(app_mod) 1abcdefgh

26 

27 

28def test_tutorial(prepare, session: Session, client: TestClient): 1abcdefgh

29 test_mod.test_create_hero(client) 1ijklmnop