Coverage for tests / test_hidden.py: 100%

30 statements  

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

1import pytest 1abcdefghij

2import typer.core 1abcdefghij

3from typer.testing import CliRunner 1abcdefghij

4 

5from tests.assets import hidden_commands as mod_command 1abcdefghij

6from tests.assets import hidden_option as mod_option 1abcdefghij

7from tests.utils import needs_rich 1abcdefghij

8 

9runner = CliRunner() 1abcdefghij

10 

11 

12@pytest.mark.parametrize( 1abcdefghij

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: 1abcdefghij

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

21 

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

23 assert result.exit_code == 0 1abcdefghij

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

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

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

27 assert "TEST_LASTNAME" in result.output 1abcdefghij

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

29 

30 

31def test_coverage_call() -> None: 1abcdefghij

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

33 assert result.exit_code == 0 1abcdefghij

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

35 

36 

37@pytest.mark.parametrize( 1abcdefghij

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: 1abcdefghij

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

46 

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

48 assert result.exit_code == 0 1abcdefghij

49 assert "visible" in result.output 1abcdefghij

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

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

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