Coverage for tests/test_tutorial/test_many_to_many/test_tutorial001.py: 100%

15 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 dirty_equals import IsList 1abcdefghijklm

6from sqlalchemy import Engine 1abcdefghijklm

7 

8from ...conftest import PrintMock 1abcdefghijklm

9 

10 

11@pytest.fixture( 1abcdefghijklm

12 name="mod", 

13 params=[ 

14 pytest.param("tutorial001"), 

15 ], 

16) 

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

18 mod = importlib.import_module(f"docs_src.tutorial.many_to_many.{request.param}") 1abcdefghijklm

19 mod.engine = database_engine 1abcdefghijklm

20 return mod 1abcdefghijklm

21 

22 

23expected_calls = [ 1abcdefghijklm

24 [ 

25 "Deadpond:", 

26 {"id": 1, "secret_name": "Dive Wilson", "age": None, "name": "Deadpond"}, 

27 ], 

28 [ 

29 "Deadpond teams:", 

30 IsList( 

31 {"id": 1, "name": "Z-Force", "headquarters": "Sister Margaret's Bar"}, 

32 {"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}, 

33 check_order=False, 

34 ), 

35 ], 

36 [ 

37 "Rusty-Man:", 

38 {"id": 2, "secret_name": "Tommy Sharp", "age": 48, "name": "Rusty-Man"}, 

39 ], 

40 [ 

41 "Rusty-Man Teams:", 

42 [{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}], 

43 ], 

44 [ 

45 "Spider-Boy:", 

46 {"id": 3, "secret_name": "Pedro Parqueador", "age": None, "name": "Spider-Boy"}, 

47 ], 

48 [ 

49 "Spider-Boy Teams:", 

50 [{"id": 2, "name": "Preventers", "headquarters": "Sharp Tower"}], 

51 ], 

52] 

53 

54 

55def test_tutorial(print_mock: PrintMock, mod: ModuleType): 1abcdefghijklm

56 mod.main() 1nopqrstuvwxyz

57 assert print_mock.calls == expected_calls 1nopqrstuvwxyz