Coverage for tests / test_tutorial / test_update / test_tutorial003_tutorial004.py: 100%

19 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 

9expected_calls = [ 1abcdefghi

10 [ 

11 "Hero 1:", 

12 {"id": 2, "name": "Spider-Boy", "secret_name": "Pedro Parqueador", "age": None}, 

13 ], 

14 [ 

15 "Hero 2:", 

16 { 

17 "id": 7, 

18 "name": "Captain North America", 

19 "secret_name": "Esteban Rogelios", 

20 "age": 93, 

21 }, 

22 ], 

23 [ 

24 "Updated hero 1:", 

25 { 

26 "id": 2, 

27 "name": "Spider-Youngster", 

28 "secret_name": "Pedro Parqueador", 

29 "age": 16, 

30 }, 

31 ], 

32 [ 

33 "Updated hero 2:", 

34 { 

35 "id": 7, 

36 "name": "Captain North America Except Canada", 

37 "secret_name": "Esteban Rogelios", 

38 "age": 110, 

39 }, 

40 ], 

41] 

42 

43 

44@pytest.fixture(name="module") 1abcdefghi

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

46 module = importlib.import_module(f"docs_src.tutorial.update.{request.param}") 1abcdefghi

47 module.engine = database_engine 1abcdefghi

48 return module 1abcdefghi

49 

50 

51@pytest.mark.parametrize( 1abcdefghi

52 "module", 

53 [ 

54 pytest.param("tutorial003_py310"), 

55 ], 

56 indirect=True, 

57) 

58def test_tutorial003(print_mock: PrintMock, module: ModuleType): 1abcdefghi

59 module.main() 1jklmnopqr

60 assert print_mock.calls == expected_calls 1jklmnopqr

61 

62 

63@pytest.mark.parametrize( 1abcdefghi

64 "module", 

65 [ 

66 pytest.param("tutorial004_py310"), 

67 ], 

68 indirect=True, 

69) 

70def test_tutorial004(print_mock: PrintMock, module: ModuleType): 1abcdefghi

71 module.main() 1stuvwxyzA

72 assert print_mock.calls == expected_calls 1stuvwxyzA