Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if config args and args_source exist #10664

Merged
merged 4 commits into from Jan 21, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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
nicoddemus marked this conversation as resolved.
Show resolved Hide resolved
self.args: List[str] = []

if TYPE_CHECKING:
from _pytest.cacheprovider import Cache
Expand Down Expand Up @@ -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)
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