Coverage for tests / test_tutorial / test_testing / test_app02.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-11-18 11:12 +0000

1import importlib 1abcdefghij

2import subprocess 1abcdefghij

3import sys 1abcdefghij

4from types import ModuleType 1abcdefghij

5 

6import pytest 1abcdefghij

7 

8 

9@pytest.fixture( 1abcdefghij

10 name="module_paths", 

11 params=[ 

12 "app02_non_an", 

13 "app02", 

14 ], 

15) 

16def get_modules_path(request: pytest.FixtureRequest) -> str: 1abcdefghij

17 return f"docs_src.testing.{request.param}" 1abcdefghij

18 

19 

20@pytest.fixture(name="main_mod") 1abcdefghij

21def get_main_mod(module_paths: str) -> ModuleType: 1abcdefghij

22 mod = importlib.import_module(f"{module_paths}.main") 1abcdefghij

23 return mod 1abcdefghij

24 

25 

26@pytest.fixture(name="test_mod") 1abcdefghij

27def get_test_mod(module_paths: str) -> ModuleType: 1abcdefghij

28 mod = importlib.import_module(f"{module_paths}.test_main") 1abcdefghij

29 return mod 1abcdefghij

30 

31 

32def test_app02(test_mod: ModuleType): 1abcdefghij

33 test_mod.test_app() 1abcdefghij

34 

35 

36def test_script(main_mod: ModuleType): 1abcdefghij

37 result = subprocess.run( 1abcdefghij

38 [sys.executable, "-m", "coverage", "run", main_mod.__file__, "--help"], 

39 capture_output=True, 

40 encoding="utf-8", 

41 ) 

42 assert "Usage" in result.stdout 1abcdefghij