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-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("tutorial001_py39"), 

14 pytest.param("tutorial001_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 "name": "Deadpond", 

33 "secret_name": "Dive Wilson", 

34 "team_id": 1, 

35 "id": 1, 

36 "age": None, 

37 }, 

38 ], 

39 [ 

40 "Created hero:", 

41 { 

42 "name": "Rusty-Man", 

43 "secret_name": "Tommy Sharp", 

44 "team_id": 2, 

45 "id": 2, 

46 "age": 48, 

47 }, 

48 ], 

49 [ 

50 "Created hero:", 

51 { 

52 "name": "Spider-Boy", 

53 "secret_name": "Pedro Parqueador", 

54 "team_id": None, 

55 "id": 3, 

56 "age": None, 

57 }, 

58 ], 

59 [ 

60 "Updated hero:", 

61 { 

62 "name": "Spider-Boy", 

63 "secret_name": "Pedro Parqueador", 

64 "team_id": 2, 

65 "id": 3, 

66 "age": None, 

67 }, 

68 ], 

69 [ 

70 "Team Wakaland:", 

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

72 ], 

73 [ 

74 "Deleted team:", 

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

76 ], 

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

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

79 ]