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

21 statements  

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

1import importlib 1abcdefgh

2import subprocess 1abcdefgh

3import sys 1abcdefgh

4from types import ModuleType 1abcdefgh

5 

6import pytest 1abcdefgh

7 

8 

9@pytest.fixture( 1abcdefgh

10 name="module_paths", 

11 params=[ 

12 "app02_py39", 

13 "app02_an_py39", 

14 ], 

15) 

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

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

18 

19 

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

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

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

23 return mod 1abcdefgh

24 

25 

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

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

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

29 return mod 1abcdefgh

30 

31 

32def test_app02(test_mod: ModuleType): 1abcdefgh

33 test_mod.test_app() 1abcdefgh

34 

35 

36def test_script(main_mod: ModuleType): 1abcdefgh

37 result = subprocess.run( 1abcdefgh

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