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

18 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-11-09 00:02 +0000

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from sqlalchemy import Engine 1abcdefghi

6 

7from ...conftest import PrintMock 1abcdefghi

8 

9 

10@pytest.fixture( 1abcdefghi

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial011_py310"), 

14 ], 

15) 

16def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghi

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

18 mod.engine = database_engine 1abcdefghi

19 return mod 1abcdefghi

20 

21 

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

23 mod.main() 1jklmnopqr

24 expected_calls = [ 1jklmnopqr

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

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

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

28 [ 

29 { 

30 "id": 7, 

31 "name": "Captain North America", 

32 "secret_name": "Esteban Rogelios", 

33 "age": 93, 

34 } 

35 ], 

36 ] 

37 calls = print_mock.calls 1jklmnopqr

38 for call in expected_calls: 1jklmnopqr

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

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

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

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