Skip to content

Commit af22d34

Browse files
authored
Merge pull request #10681 from pytest-dev/backport-10664-to-7.2.x
[7.2.x] Check if config args and args_source exist
2 parents 9c103ae + d1b9660 commit af22d34

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ Prashant Sharma
286286
Pulkit Goyal
287287
Punyashloka Biswal
288288
Quentin Pradet
289+
q0w
289290
Ralf Schmitt
290291
Ram Rachum
291292
Ralph Giles

changelog/10626.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix crash if ``--fixtures`` and ``--help`` are passed at the same time.

src/_pytest/config/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,8 @@ def __init__(
998998
self.hook.pytest_addoption.call_historic(
999999
kwargs=dict(parser=self._parser, pluginmanager=self.pluginmanager)
10001000
)
1001+
self.args_source = Config.ArgsSource.ARGS
1002+
self.args: List[str] = []
10011003

10021004
if TYPE_CHECKING:
10031005
from _pytest.cacheprovider import Cache
@@ -1337,8 +1339,8 @@ def _get_unknown_ini_keys(self) -> List[str]:
13371339

13381340
def parse(self, args: List[str], addopts: bool = True) -> None:
13391341
# Parse given cmdline arguments into this config object.
1340-
assert not hasattr(
1341-
self, "args"
1342+
assert (
1343+
self.args == []
13421344
), "can only parse cmdline args at most once per Config object"
13431345
self.hook.pytest_addhooks.call_historic(
13441346
kwargs=dict(pluginmanager=self.pluginmanager)

testing/python/fixtures.py

+4
Original file line numberDiff line numberDiff line change
@@ -3338,6 +3338,10 @@ def test_funcarg_compat(self, pytester: Pytester) -> None:
33383338
config = pytester.parseconfigure("--funcargs")
33393339
assert config.option.showfixtures
33403340

3341+
def test_show_help(self, pytester: Pytester) -> None:
3342+
result = pytester.runpytest("--fixtures", "--help")
3343+
assert not result.ret
3344+
33413345
def test_show_fixtures(self, pytester: Pytester) -> None:
33423346
result = pytester.runpytest("--fixtures")
33433347
result.stdout.fnmatch_lines(

0 commit comments

Comments
 (0)