Coverage for tests/test_tutorial/test_code_structure/test_tutorial002.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-27 00:03 +0000

1from unittest.mock import patch 1klmnopqrst

2 

3from sqlmodel import create_engine 1klmnopqrst

4 

5from ...conftest import get_testing_print_function 1klmnopqrst

6 

7expected_calls = [ 1klmnopqrst

8 [ 

9 "Created hero:", 

10 { 

11 "id": 1, 

12 "name": "Deadpond", 

13 "age": None, 

14 "secret_name": "Dive Wilson", 

15 "team_id": 1, 

16 }, 

17 ], 

18 [ 

19 "Hero's team:", 

20 {"name": "Z-Force", "headquarters": "Sister Margaret's Bar", "id": 1}, 

21 ], 

22] 

23 

24 

25def test_tutorial(): 1klmnopqrst

26 from docs_src.tutorial.code_structure.tutorial002 import app, database 1abcdefghij

27 

28 database.sqlite_url = "sqlite://" 1abcdefghij

29 database.engine = create_engine(database.sqlite_url) 1abcdefghij

30 app.engine = database.engine 1abcdefghij

31 calls = [] 1abcdefghij

32 

33 new_print = get_testing_print_function(calls) 1abcdefghij

34 

35 with patch("builtins.print", new=new_print): 1abcdefghij

36 app.main() 1abcdefghij

37 assert calls == expected_calls 1abcdefghij