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

19 statements  

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

1import importlib 1abcdefghijklm

2from types import ModuleType 1abcdefghijklm

3 

4import pytest 1abcdefghijklm

5from sqlalchemy import Engine 1abcdefghijklm

6 

7from ...conftest import PrintMock 1abcdefghijklm

8 

9expected_calls = [ 1abcdefghijklm

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") 1abcdefghijklm

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

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

34 module.engine = database_engine 1abcdefghijklm

35 return module 1abcdefghijklm

36 

37 

38@pytest.mark.parametrize( 1abcdefghijklm

39 "module", 

40 [ 

41 pytest.param("tutorial001"), 

42 ], 

43 indirect=True, 

44) 

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

46 module.main() 1nopqrstuvwxyz

47 assert print_mock.calls == expected_calls 1nopqrstuvwxyz

48 

49 

50@pytest.mark.parametrize( 1abcdefghijklm

51 "module", 

52 [ 

53 pytest.param("tutorial002"), 

54 ], 

55 indirect=True, 

56) 

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

58 module.main() 1ABCDEFGHIJKLM

59 assert print_mock.calls == expected_calls 1ABCDEFGHIJKLM