Coverage for tests / test_tutorial / test_relationship_attributes / test_delete_records_relationship / test_tutorial001.py: 100%

14 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 

9 

10@pytest.fixture( 1abcdefgh

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial001_py310"), 

14 ], 

15) 

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

17 mod = importlib.import_module( 1abcdefgh

18 f"docs_src.tutorial.relationship_attributes.cascade_delete_relationships.{request.param}" 

19 ) 

20 mod.sqlite_url = "sqlite://" 1abcdefgh

21 mod.engine = create_engine(mod.sqlite_url) 1abcdefgh

22 return mod 1abcdefgh

23 

24 

25def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefgh

26 mod.main() 1ijklmnop

27 assert print_mock.calls == [ 1ijklmnop

28 [ 

29 "Created hero:", 

30 { 

31 "name": "Deadpond", 

32 "secret_name": "Dive Wilson", 

33 "team_id": 1, 

34 "id": 1, 

35 "age": None, 

36 }, 

37 ], 

38 [ 

39 "Created hero:", 

40 { 

41 "name": "Rusty-Man", 

42 "secret_name": "Tommy Sharp", 

43 "team_id": 2, 

44 "id": 2, 

45 "age": 48, 

46 }, 

47 ], 

48 [ 

49 "Created hero:", 

50 { 

51 "name": "Spider-Boy", 

52 "secret_name": "Pedro Parqueador", 

53 "team_id": None, 

54 "id": 3, 

55 "age": None, 

56 }, 

57 ], 

58 [ 

59 "Updated hero:", 

60 { 

61 "name": "Spider-Boy", 

62 "secret_name": "Pedro Parqueador", 

63 "team_id": 2, 

64 "id": 3, 

65 "age": None, 

66 }, 

67 ], 

68 [ 

69 "Team Wakaland:", 

70 {"name": "Wakaland", "id": 3, "headquarters": "Wakaland Capital City"}, 

71 ], 

72 [ 

73 "Deleted team:", 

74 {"name": "Wakaland", "id": 3, "headquarters": "Wakaland Capital City"}, 

75 ], 

76 ["Black Lion not found:", None], 

77 ["Princess Sure-E not found:", None], 

78 ]