Don't treat ini keys defined in conftest.py as invalid (#7384)
This commit is contained in:
parent
88a187aae8
commit
4cc4ebf3c9
|
@ -1054,7 +1054,6 @@ class Config:
|
|||
args, namespace=copy.copy(self.option)
|
||||
)
|
||||
self._validate_plugins()
|
||||
self._validate_keys()
|
||||
if self.known_args_namespace.confcutdir is None and self.inifile:
|
||||
confcutdir = py.path.local(self.inifile).dirname
|
||||
self.known_args_namespace.confcutdir = confcutdir
|
||||
|
@ -1077,6 +1076,7 @@ class Config:
|
|||
)
|
||||
else:
|
||||
raise
|
||||
self._validate_keys()
|
||||
|
||||
def _checkversion(self):
|
||||
import pytest
|
||||
|
|
|
@ -203,6 +203,15 @@ class TestParseIni:
|
|||
"""
|
||||
[pytest]
|
||||
minversion = 5.0.0
|
||||
""",
|
||||
[],
|
||||
[],
|
||||
"",
|
||||
),
|
||||
(
|
||||
"""
|
||||
[pytest]
|
||||
conftest_ini_key = 1
|
||||
""",
|
||||
[],
|
||||
[],
|
||||
|
@ -213,16 +222,25 @@ class TestParseIni:
|
|||
def test_invalid_ini_keys(
|
||||
self, testdir, ini_file_text, invalid_keys, stderr_output, exception_text
|
||||
):
|
||||
testdir.makeconftest(
|
||||
"""
|
||||
def pytest_addoption(parser):
|
||||
parser.addini("conftest_ini_key", "")
|
||||
"""
|
||||
)
|
||||
testdir.tmpdir.join("pytest.ini").write(textwrap.dedent(ini_file_text))
|
||||
|
||||
config = testdir.parseconfig()
|
||||
assert sorted(config._get_unknown_ini_keys()) == sorted(invalid_keys)
|
||||
|
||||
result = testdir.runpytest()
|
||||
result.stderr.fnmatch_lines(stderr_output)
|
||||
|
||||
if stderr_output:
|
||||
if exception_text:
|
||||
with pytest.raises(pytest.fail.Exception, match=exception_text):
|
||||
testdir.runpytest("--strict-config")
|
||||
else:
|
||||
testdir.runpytest("--strict-config")
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"ini_file_text, exception_text",
|
||||
|
|
Loading…
Reference in New Issue