Skip to content

Commit

Permalink
Initialize args and args_source during Config.__init__
Browse files Browse the repository at this point in the history
Closes #10626

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
  • Loading branch information
q0w and nicoddemus committed Jan 21, 2023
1 parent 6a714d7 commit bd7919e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -290,6 +290,7 @@ Prashant Sharma
Pulkit Goyal
Punyashloka Biswal
Quentin Pradet
q0w
Ralf Schmitt
Ralph Giles
Ram Rachum
Expand Down
1 change: 1 addition & 0 deletions changelog/10626.bugfix.rst
@@ -0,0 +1 @@
Fix crash if ``--fixtures`` and ``--help`` are passed at the same time.
6 changes: 4 additions & 2 deletions src/_pytest/config/__init__.py
Expand Up @@ -1005,6 +1005,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
Expand Down Expand Up @@ -1344,8 +1346,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)
Expand Down
4 changes: 4 additions & 0 deletions testing/python/fixtures.py
Expand Up @@ -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(
Expand Down

0 comments on commit bd7919e

Please sign in to comment.