Coverage for tests / test_tutorial / test_printing / test_tutorial004.py: 100%

17 statements  

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

1import platform 1abchdefg

2import subprocess 1abchdefg

3import sys 1abchdefg

4 

5import pytest 1abchdefg

6from typer.testing import CliRunner 1abchdefg

7 

8import docs_src.printing.tutorial004_py39 as mod 1abchdefg

9 

10app = mod.app 1abchdefg

11 

12runner = CliRunner() 1abchdefg

13 

14 

15@pytest.mark.xfail( 1abchdefg

16 condition=((platform.system() == "Windows") and (sys.version_info < (3, 10))), 

17 reason="On Windows with Python 3.9, output is in stdout instead of stderr", 

18) 

19def test_cli(): 1abchdefg

20 result = runner.invoke(app) 1abchdefg

21 assert result.exit_code == 0 1abchdefg

22 assert result.stdout == "" 1abchdefg

23 assert "Here is something written to standard error" in result.stderr 1abcdefg

24 

25 

26def test_script(): 1abchdefg

27 result = subprocess.run( 1abchdefg

28 [sys.executable, "-m", "coverage", "run", mod.__file__, "--help"], 

29 capture_output=True, 

30 encoding="utf-8", 

31 ) 

32 assert "Usage" in result.stdout 1abchdefg