Coverage for tests / test_hidden.py: 100%

30 statements  

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

1import pytest 1abcdefg

2import typer.core 1abcdefg

3from typer.testing import CliRunner 1abcdefg

4 

5from tests.assets import hidden_commands as mod_command 1abcdefg

6from tests.assets import hidden_option as mod_option 1abcdefg

7from tests.utils import needs_rich 1abcdefg

8 

9runner = CliRunner() 1abcdefg

10 

11 

12@pytest.mark.parametrize( 1abcdefg

13 "use_rich", 

14 [ 

15 pytest.param(False), 

16 pytest.param(True, marks=needs_rich), 

17 ], 

18) 

19def test_hidden_option(monkeypatch: pytest.MonkeyPatch, use_rich: bool) -> None: 1abcdefg

20 monkeypatch.setattr(typer.core, "HAS_RICH", use_rich) 1abcdefg

21 

22 result = runner.invoke(mod_option.app, ["--help"]) 1abcdefg

23 assert result.exit_code == 0 1abcdefg

24 assert "Say hello" in result.output 1abcdefg

25 assert "--name" not in result.output 1abcdefg

26 assert "/lastname" in result.output 1abcdefg

27 assert "TEST_LASTNAME" in result.output 1abcdefg

28 assert "(dynamic)" in result.output 1abcdefg

29 

30 

31def test_coverage_call() -> None: 1abcdefg

32 result = runner.invoke(mod_option.app) 1abcdefg

33 assert result.exit_code == 0 1abcdefg

34 assert "Hello John Doe, it seems you have 42" in result.output 1abcdefg

35 

36 

37@pytest.mark.parametrize( 1abcdefg

38 "use_rich", 

39 [ 

40 pytest.param(False), 

41 pytest.param(True, marks=needs_rich), 

42 ], 

43) 

44def test_hidden_commands(monkeypatch: pytest.MonkeyPatch, use_rich: bool) -> None: 1abcdefg

45 monkeypatch.setattr(typer.core, "HAS_RICH", use_rich) 1abcdefg

46 

47 result = runner.invoke(mod_command.app, ["--help"]) 1abcdefg

48 assert result.exit_code == 0 1abcdefg

49 assert "visible" in result.output 1abcdefg

50 assert "hidden-decorated" not in result.output 1abcdefg

51 assert "hidden-var" not in result.output 1abcdefg

52 assert "hidden-subgroup" not in result.output 1abcdefg