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

20 statements  

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

1import importlib 1abcdefgh

2from types import ModuleType 1abcdefgh

3 

4import pytest 1abcdefgh

5from sqlmodel import create_engine 1abcdefgh

6 

7from ...conftest import PrintMock 1abcdefgh

8 

9expected_calls = [ 1abcdefgh

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

32def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefgh

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

34 module.sqlite_url = "sqlite://" 1abcdefgh

35 module.engine = create_engine(module.sqlite_url) 1abcdefgh

36 return module 1abcdefgh

37 

38 

39@pytest.mark.parametrize( 1abcdefgh

40 "module", 

41 [ 

42 pytest.param("tutorial001_py310"), 

43 ], 

44 indirect=True, 

45) 

46def test_tutorial001(print_mock: PrintMock, module: ModuleType): 1abcdefgh

47 module.main() 1ijklmnop

48 assert print_mock.calls == expected_calls 1ijklmnop

49 

50 

51@pytest.mark.parametrize( 1abcdefgh

52 "module", 

53 [ 

54 pytest.param("tutorial002_py310"), 

55 ], 

56 indirect=True, 

57) 

58def test_tutorial002(print_mock: PrintMock, module: ModuleType): 1abcdefgh

59 module.main() 1qrstuvwx

60 assert print_mock.calls == expected_calls 1qrstuvwx