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

14 statements  

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

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from sqlmodel import create_engine 1abcdefghi

6 

7from ....conftest import PrintMock, needs_py310 1abcdefghi

8 

9 

10@pytest.fixture( 1abcdefghi

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial003_py39"), 

14 pytest.param("tutorial003_py310", marks=needs_py310), 

15 ], 

16) 

17def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi

18 mod = importlib.import_module( 1abcdefghi

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

20 ) 

21 mod.sqlite_url = "sqlite://" 1abcdefghi

22 mod.engine = create_engine(mod.sqlite_url) 1abcdefghi

23 return mod 1abcdefghi

24 

25 

26def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghi

27 mod.main() 1jklmnopqr

28 assert print_mock.calls == [ 1jklmnopqr

29 [ 

30 "Created hero:", 

31 { 

32 "age": None, 

33 "id": 1, 

34 "name": "Deadpond", 

35 "secret_name": "Dive Wilson", 

36 "team_id": 1, 

37 }, 

38 ], 

39 [ 

40 "Created hero:", 

41 { 

42 "age": 48, 

43 "id": 2, 

44 "name": "Rusty-Man", 

45 "secret_name": "Tommy Sharp", 

46 "team_id": 2, 

47 }, 

48 ], 

49 [ 

50 "Created hero:", 

51 { 

52 "age": None, 

53 "id": 3, 

54 "name": "Spider-Boy", 

55 "secret_name": "Pedro Parqueador", 

56 "team_id": None, 

57 }, 

58 ], 

59 [ 

60 "Updated hero:", 

61 { 

62 "age": None, 

63 "id": 3, 

64 "name": "Spider-Boy", 

65 "secret_name": "Pedro Parqueador", 

66 "team_id": 2, 

67 }, 

68 ], 

69 [ 

70 "Team Wakaland:", 

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

72 ], 

73 [ 

74 "Deleted team:", 

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

76 ], 

77 [ 

78 "Black Lion has no team:", 

79 { 

80 "age": 35, 

81 "id": 4, 

82 "name": "Black Lion", 

83 "secret_name": "Trevor Challa", 

84 "team_id": None, 

85 }, 

86 ], 

87 [ 

88 "Princess Sure-E has no team:", 

89 { 

90 "age": None, 

91 "id": 5, 

92 "name": "Princess Sure-E", 

93 "secret_name": "Sure-E", 

94 "team_id": None, 

95 }, 

96 ], 

97 ]