throw if addoption called after preparse with no default
This commit is contained in:
parent
4d7a962ca0
commit
95e0e2ba8c
1
AUTHORS
1
AUTHORS
|
@ -185,6 +185,7 @@ Katerina Koukiou
|
||||||
Keri Volans
|
Keri Volans
|
||||||
Kevin Cox
|
Kevin Cox
|
||||||
Kevin J. Foley
|
Kevin J. Foley
|
||||||
|
Kevin Santana
|
||||||
Kodi B. Arfer
|
Kodi B. Arfer
|
||||||
Kostis Anagnostopoulos
|
Kostis Anagnostopoulos
|
||||||
Kristoffer Nordström
|
Kristoffer Nordström
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
`Parser.addoption` now throws a value error if an attempt is made at adding an option
|
||||||
|
after the pre_parsing process without including a default.
|
|
@ -362,6 +362,11 @@ class OptionGroup:
|
||||||
results in help showing ``--two-words`` only, but ``--twowords`` gets
|
results in help showing ``--two-words`` only, but ``--twowords`` gets
|
||||||
accepted **and** the automatic destination is in ``args.twowords``.
|
accepted **and** the automatic destination is in ``args.twowords``.
|
||||||
"""
|
"""
|
||||||
|
if getattr(self.parser, "after_preparse", False) and "default" not in attrs:
|
||||||
|
raise ValueError(
|
||||||
|
"Cannot add options without default after initial conftest discovery"
|
||||||
|
)
|
||||||
|
|
||||||
conflict = set(optnames).intersection(
|
conflict = set(optnames).intersection(
|
||||||
name for opt in self.options for name in opt.names()
|
name for opt in self.options for name in opt.names()
|
||||||
)
|
)
|
||||||
|
|
|
@ -78,6 +78,21 @@ class TestPytestPluginInteractions:
|
||||||
)
|
)
|
||||||
assert config.option.test123
|
assert config.option.test123
|
||||||
|
|
||||||
|
def test_do_option_postinit_nodefault(self, pytester: Pytester) -> None:
|
||||||
|
config = pytester.parseconfigure()
|
||||||
|
assert not hasattr(config.option, "deadbeef")
|
||||||
|
p = pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption('--deadbeef', action="store_true")
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
config.pluginmanager._importconftest(
|
||||||
|
p, importmode="prepend", rootpath=pytester.path
|
||||||
|
)
|
||||||
|
assert not hasattr(config.option, "deadbeef")
|
||||||
|
|
||||||
def test_configure(self, pytester: Pytester) -> None:
|
def test_configure(self, pytester: Pytester) -> None:
|
||||||
config = pytester.parseconfig()
|
config = pytester.parseconfig()
|
||||||
values = []
|
values = []
|
||||||
|
|
Loading…
Reference in New Issue