Pytest¶
Important
For these helpers to work, you need to install click_extra’s additional dependencies from the pytest extra group:
$ pip install click_extra[pytest]
Utility functions¶
Todo
Write example and tutorial.
Fixtures¶
Todo
Write example and tutorial.
click_extra.pytest API¶
Pytest fixtures and marks to help testing Click CLIs.
- click_extra.pytest.runner()[source]
Runner fixture for
click_extra.testing.CliRunner.Pins
HOME(and its platform-specific equivalents) to a subdirectory of the runner’s isolated filesystem so configuration-file discovery is deterministic and independent of the ambient environment. Without this, the handful of tests asserting on the config-search debug output depend on the caller’sHOME: hermetic builders setHOME=/homeless-shelter, which would otherwise leak into those assertions.The environment is patched directly rather than through the
monkeypatchfixture on purpose: depending onmonkeypatchhere would tear it down afterisolated_filesystemremoved the working directory it tries to restore, breaking unrelated tests thatchdirwithin the runner.
- click_extra.pytest.invoke(runner)[source]
Invoke fixture shorthand for
click_extra.testing.CliRunner.invoke().
- click_extra.pytest.command_decorators(no_commands=False, no_groups=False, no_click=False, no_cloup=False, no_extra=False, with_parenthesis=True, with_types=False)[source]
Returns collection of Pytest parameters to test all command-like decorators.
- Return type:
- Returns:
Pytest parameters covering each command-like decorator variant:
click.commandclick.command()cloup.commandcloup.command()click_extra.commandclick_extra.command()click.groupclick.group()cloup.groupcloup.group()click_extra.groupclick_extra.group()
- click_extra.pytest.option_decorators(no_options=False, no_arguments=False, no_click=False, no_cloup=False, no_extra=False, with_parenthesis=True, with_types=False)[source]
Returns collection of Pytest parameters to test all parameter-like decorators.
- Return type:
- Returns:
Pytest parameters covering each parameter-like decorator variant:
click.optionclick.option()cloup.optioncloup.option()click_extra.optionclick_extra.option()click.argumentclick.argument()cloup.argumentcloup.argument()click_extra.argumentclick_extra.argument()
- click_extra.pytest.create_config(tmp_path)[source]
A generic fixture to produce a temporary configuration file.
- click_extra.pytest.assert_output_regex()[source]
An assert-like utility for Pytest to compare CLI output against the regex.
Designed for the regexes defined above.