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

14 statements  

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

1import importlib 1abcdefghijklm

2from types import ModuleType 1abcdefghijklm

3 

4import pytest 1abcdefghijklm

5from sqlalchemy import Engine 1abcdefghijklm

6 

7from ....conftest import PrintMock 1abcdefghijklm

8 

9 

10@pytest.fixture( 1abcdefghijklm

11 name="mod", 

12 params=[ 

13 pytest.param("tutorial001"), 

14 ], 

15) 

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

17 mod = importlib.import_module( 1abcdefghijklm

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

19 ) 

20 mod.engine = database_engine 1abcdefghijklm

21 return mod 1abcdefghijklm

22 

23 

24expected_calls = [ 1abcdefghijklm

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): 1abcdefghijklm

59 mod.main() 1nopqrstuvwxyz

60 assert print_mock.calls == expected_calls 1nopqrstuvwxyz