@@ -29,6 +29,12 @@ def traverse_commands(command: click.Command, args: t.List[str]) -> t.Iterator[t
2929 yield from traverse_commands (sub , args + ["--type" , context_type , name ])
3030
3131
32+ def pytest_generate_tests (metafunc : pytest .Metafunc ) -> None :
33+ m = next (metafunc .definition .iter_markers ("help_page" ), None )
34+ if m is not None and "base_cmd" in m .kwargs :
35+ metafunc .parametrize ("args" , traverse_commands (main , m .kwargs ["base_cmd" ]), ids = " " .join )
36+
37+
3238@pytest .fixture
3339def no_api (monkeypatch : pytest .MonkeyPatch ) -> None :
3440 @property # type: ignore
@@ -38,30 +44,28 @@ def getter(self: t.Any) -> None:
3844 monkeypatch .setattr ("pulp_glue.common.context.PulpContext.api" , getter )
3945
4046
41- @pytest .mark .help_page
42- def test_access_help (no_api : None , subtests : pytest .Subtests ) -> None :
43- """Test, that all help screens are accessible without touching the api property."""
47+ @pytest .mark .help_page (base_cmd = [])
48+ def test_accessing_the_help_page_does_not_invoke_api (
49+ no_api : None ,
50+ args : list [str ],
51+ ) -> None :
4452 runner = CliRunner ()
45- for args in traverse_commands (main , []):
46- with subtests .test (msg = " " .join (args )):
47- result = runner .invoke (main , args + ["--help" ], catch_exceptions = False )
48-
49- if result .exit_code == 2 :
50- assert (
51- "not available in this context" in result .stdout
52- or "not available in this context" in result .stderr
53- )
54- else :
55- assert result .exit_code == 0
56- assert result .stdout .startswith ("Usage:" ) or result .stdout .startswith (
57- "DeprecationWarning:"
58- )
53+ result = runner .invoke (main , args + ["--help" ], catch_exceptions = False )
54+
55+ if result .exit_code == 2 :
56+ assert (
57+ "not available in this context" in result .stdout
58+ or "not available in this context" in result .stderr
59+ )
60+ else :
61+ assert result .exit_code == 0
62+ assert result .stdout .startswith ("Usage:" ) or result .stdout .startswith ("DeprecationWarning:" )
5963
6064
6165@pytest .mark .parametrize (
6266 "command,options" ,
6367 [
64- (
68+ pytest . param (
6569 [
6670 "file" ,
6771 "repository" ,
0 commit comments