Coverage for tests / test_tutorial / test_update / test_tutorial001_tutorial002.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:", 

12 { 

13 "id": 2, 

14 "name": "Spider-Boy", 

15 "secret_name": "Pedro Parqueador", 

16 "age": None, 

17 }, 

18 ], 

19 [ 

20 "Updated hero:", 

21 { 

22 "id": 2, 

23 "name": "Spider-Boy", 

24 "secret_name": "Pedro Parqueador", 

25 "age": 16, 

26 }, 

27 ], 

28] 

29 

30 

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

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

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

34 module.engine = database_engine 1abcdefghi

35 return module 1abcdefghi

36 

37 

38@pytest.mark.parametrize( 1abcdefghi

39 "module", 

40 [ 

41 pytest.param("tutorial001_py310"), 

42 ], 

43 indirect=True, 

44) 

45def test_tutorial001(print_mock: PrintMock, module: ModuleType): 1abcdefghi

46 module.main() 1jklmnopqr

47 assert print_mock.calls == expected_calls 1jklmnopqr

48 

49 

50@pytest.mark.parametrize( 1abcdefghi

51 "module", 

52 [ 

53 pytest.param("tutorial002_py310"), 

54 ], 

55 indirect=True, 

56) 

57def test_tutorial002(print_mock: PrintMock, module: ModuleType): 1abcdefghi

58 module.main() 1stuvwxyzA

59 assert print_mock.calls == expected_calls 1stuvwxyzA