Skip to content
Myr

test_hidden.py

This file

Path

tests/test_hidden.py

52 lines · 1.5 KiB · Python

Last changed by

🐛 Ensure that hidden commands are not shown when Rich markup is disabled (#1812)Sofie Van Landeghembefore adoption9172486

History of this file

Take it

1import pytest2import typer.core3from typer.testing import CliRunner45from tests.assets import hidden_commands as mod_command6from tests.assets import hidden_option as mod_option7from tests.utils import needs_rich89runner = CliRunner()101112@pytest.mark.parametrize(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:20    monkeypatch.setattr(typer.core, "HAS_RICH", use_rich)2122    result = runner.invoke(mod_option.app, ["--help"])23    assert result.exit_code == 024    assert "Say hello" in result.output25    assert "--name" not in result.output26    assert "/lastname" in result.output27    assert "TEST_LASTNAME" in result.output28    assert "(dynamic)" in result.output293031def test_coverage_call() -> None:32    result = runner.invoke(mod_option.app)33    assert result.exit_code == 034    assert "Hello John Doe, it seems you have 42" in result.output353637@pytest.mark.parametrize(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:45    monkeypatch.setattr(typer.core, "HAS_RICH", use_rich)4647    result = runner.invoke(mod_command.app, ["--help"])48    assert result.exit_code == 049    assert "visible" in result.output50    assert "hidden-decorated" not in result.output51    assert "hidden-var" not in result.output52    assert "hidden-subgroup" not in result.output