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

14 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-11-09 00:02 +0000

1import importlib 1abcdefghi

2from types import ModuleType 1abcdefghi

3 

4import pytest 1abcdefghi

5from sqlalchemy import Engine 1abcdefghi

6 

7from ....conftest import PrintMock 1abcdefghi

8 

9 

10@pytest.fixture( 1abcdefghi

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial001_py310"), 

14 ], 

15) 

16def get_module(request: pytest.FixtureRequest, database_engine: Engine) -> ModuleType: 1abcdefghi

17 mod = importlib.import_module( 1abcdefghi

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

19 ) 

20 mod.engine = database_engine 1abcdefghi

21 return mod 1abcdefghi

22 

23 

24expected_calls = [ 1abcdefghi

25 [ 

26 "Created hero:", 

27 { 

28 "name": "Deadpond", 

29 "age": None, 

30 "team_id": 1, 

31 "id": 1, 

32 "secret_name": "Dive Wilson", 

33 }, 

34 ], 

35 [ 

36 "Created hero:", 

37 { 

38 "name": "Rusty-Man", 

39 "age": 48, 

40 "team_id": 2, 

41 "id": 2, 

42 "secret_name": "Tommy Sharp", 

43 }, 

44 ], 

45 [ 

46 "Created hero:", 

47 { 

48 "name": "Spider-Boy", 

49 "age": None, 

50 "team_id": None, 

51 "id": 3, 

52 "secret_name": "Pedro Parqueador", 

53 }, 

54 ], 

55] 

56 

57 

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

59 mod.main() 1jklmnopqr

60 assert print_mock.calls == expected_calls 1jklmnopqr