Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Test requirements
pytest>=9.0.0,<9.1
pytest>=7.0.0,<9.1
pytest-xdist
python-gnupg>=0.5.0,<0.6
trustme>=1.1.0,<1.3
Expand Down
40 changes: 22 additions & 18 deletions tests/test_help_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def traverse_commands(command: click.Command, args: t.List[str]) -> t.Iterator[t
yield from traverse_commands(sub, args + ["--type", context_type, name])


def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
m = next(metafunc.definition.iter_markers("help_page"), None)
if m is not None and "base_cmd" in m.kwargs:
metafunc.parametrize("args", traverse_commands(main, m.kwargs["base_cmd"]), ids=" ".join)


@pytest.fixture
def no_api(monkeypatch: pytest.MonkeyPatch) -> None:
@property # type: ignore
Expand All @@ -38,30 +44,28 @@ def getter(self: t.Any) -> None:
monkeypatch.setattr("pulp_glue.common.context.PulpContext.api", getter)


@pytest.mark.help_page
def test_access_help(no_api: None, subtests: pytest.Subtests) -> None:
"""Test, that all help screens are accessible without touching the api property."""
@pytest.mark.help_page(base_cmd=[])
def test_accessing_the_help_page_does_not_invoke_api(
no_api: None,
args: list[str],
) -> None:
runner = CliRunner()
for args in traverse_commands(main, []):
with subtests.test(msg=" ".join(args)):
result = runner.invoke(main, args + ["--help"], catch_exceptions=False)

if result.exit_code == 2:
assert (
"not available in this context" in result.stdout
or "not available in this context" in result.stderr
)
else:
assert result.exit_code == 0
assert result.stdout.startswith("Usage:") or result.stdout.startswith(
"DeprecationWarning:"
)
result = runner.invoke(main, args + ["--help"], catch_exceptions=False)

if result.exit_code == 2:
assert (
"not available in this context" in result.stdout
or "not available in this context" in result.stderr
)
else:
assert result.exit_code == 0
assert result.stdout.startswith("Usage:") or result.stdout.startswith("DeprecationWarning:")


@pytest.mark.parametrize(
"command,options",
[
(
pytest.param(
[
"file",
"repository",
Expand Down
Loading