Coverage for tests / test_tutorial / test_where / test_tutorial004.py: 100%

19 statements  

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

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from sqlmodel import create_engine 1abcdefghi

6 

7from ...conftest import PrintMock, needs_py310 1abcdefghi

8 

9 

10@pytest.fixture( 1abcdefghi

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial004_py39"), 

14 pytest.param("tutorial004_py310", marks=needs_py310), 

15 ], 

16) 

17def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi

18 mod = importlib.import_module(f"docs_src.tutorial.where.{request.param}") 1abcdefghi

19 mod.sqlite_url = "sqlite://" 1abcdefghi

20 mod.engine = create_engine(mod.sqlite_url) 1abcdefghi

21 return mod 1abcdefghi

22 

23 

24def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghi

25 mod.main() 1jklmnopqr

26 expected_calls = [ 1jklmnopqr

27 [{"id": 5, "name": "Black Lion", "secret_name": "Trevor Challa", "age": 35}], 

28 [{"id": 6, "name": "Dr. Weird", "secret_name": "Steve Weird", "age": 36}], 

29 [{"id": 3, "name": "Rusty-Man", "secret_name": "Tommy Sharp", "age": 48}], 

30 [ 

31 { 

32 "id": 7, 

33 "name": "Captain North America", 

34 "secret_name": "Esteban Rogelios", 

35 "age": 93, 

36 } 

37 ], 

38 ] 

39 calls = print_mock.calls 1jklmnopqr

40 for call in expected_calls: 1jklmnopqr

41 assert call in calls, "This expected item should be in the list" 1jklmnopqr

42 # Now that this item was checked, remove it from the list 

43 calls.pop(calls.index(call)) 1jklmnopqr

44 assert len(calls) == 0, "The list should only have the expected items" 1jklmnopqr