Coverage for tests / test_tutorial / test_many_to_many / 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(f"docs_src.tutorial.many_to_many.{request.param}") 1abcdefghi

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

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

21 return mod 1abcdefghi

22 

23 

24expected_calls = [ 1abcdefghi

25 [ 

26 "Deadpond:", 

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

28 ], 

29 [ 

30 "Deadpond teams:", 

31 [ 

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

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

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

56 mod.main() 1jklmnopqr

57 assert print_mock.calls == expected_calls 1jklmnopqr