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

15 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.define_relationship_attributes.{request.param}" 

20 ) 

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

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

23 return mod 1abcdefghi

24 

25 

26expected_calls = [ 1abcdefghi

27 [ 

28 "Created hero:", 

29 { 

30 "name": "Deadpond", 

31 "age": None, 

32 "team_id": 1, 

33 "id": 1, 

34 "secret_name": "Dive Wilson", 

35 }, 

36 ], 

37 [ 

38 "Created hero:", 

39 { 

40 "name": "Rusty-Man", 

41 "age": 48, 

42 "team_id": 2, 

43 "id": 2, 

44 "secret_name": "Tommy Sharp", 

45 }, 

46 ], 

47 [ 

48 "Created hero:", 

49 { 

50 "name": "Spider-Boy", 

51 "age": None, 

52 "team_id": None, 

53 "id": 3, 

54 "secret_name": "Pedro Parqueador", 

55 }, 

56 ], 

57] 

58 

59 

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

61 mod.main() 1jklmnopqr

62 assert print_mock.calls == expected_calls 1jklmnopqr