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

21 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-03-26 21:46 +0000

1import importlib 1abcdefg

2import subprocess 1abcdefg

3import sys 1abcdefg

4from types import ModuleType 1abcdefg

5 

6import pytest 1abcdefg

7 

8 

9@pytest.fixture( 1abcdefg

10 name="module_paths", 

11 params=[ 

12 "app02_py310", 

13 "app02_an_py310", 

14 ], 

15) 

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

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

18 

19 

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

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

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

23 return mod 1abcdefg

24 

25 

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

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

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

29 return mod 1abcdefg

30 

31 

32def test_app02(test_mod: ModuleType): 1abcdefg

33 test_mod.test_app() 1abcdefg

34 

35 

36def test_script(main_mod: ModuleType): 1abcdefg

37 result = subprocess.run( 1abcdefg

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 1abcdefg