diff --git a/AUTHORS b/AUTHORS index 7cf1748e606..f345c0cab93 100644 --- a/AUTHORS +++ b/AUTHORS @@ -290,6 +290,7 @@ Prashant Sharma Pulkit Goyal Punyashloka Biswal Quentin Pradet +q0w Ralf Schmitt Ralph Giles Ram Rachum diff --git a/changelog/10626.bugfix.rst b/changelog/10626.bugfix.rst new file mode 100644 index 00000000000..c3c7ef77840 --- /dev/null +++ b/changelog/10626.bugfix.rst @@ -0,0 +1 @@ +Fix crash if ``--fixtures`` and ``--help`` are passed at the same time. diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 25f156f8b20..bd2611df6b1 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -998,6 +998,8 @@ def __init__( self.hook.pytest_addoption.call_historic( kwargs=dict(parser=self._parser, pluginmanager=self.pluginmanager) ) + self.args_source = Config.ArgsSource.ARGS + self.args: List[str] = [] if TYPE_CHECKING: from _pytest.cacheprovider import Cache @@ -1337,8 +1339,8 @@ def _get_unknown_ini_keys(self) -> List[str]: def parse(self, args: List[str], addopts: bool = True) -> None: # Parse given cmdline arguments into this config object. - assert not hasattr( - self, "args" + assert ( + self.args == [] ), "can only parse cmdline args at most once per Config object" self.hook.pytest_addhooks.call_historic( kwargs=dict(pluginmanager=self.pluginmanager) diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 3ce5cb34ddd..d996f80bb93 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -3338,6 +3338,10 @@ def test_funcarg_compat(self, pytester: Pytester) -> None: config = pytester.parseconfigure("--funcargs") assert config.option.showfixtures + def test_show_help(self, pytester: Pytester) -> None: + result = pytester.runpytest("--fixtures", "--help") + assert not result.ret + def test_show_fixtures(self, pytester: Pytester) -> None: result = pytester.runpytest("--fixtures") result.stdout.fnmatch_lines(