Don't treat ini keys defined in conftest.py as invalid (#7384)

This commit is contained in:
Gleb Nikonorov 2020-06-18 11:58:41 -04:00 committed by GitHub
parent 88a187aae8
commit 4cc4ebf3c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -1054,7 +1054,6 @@ class Config:
args, namespace=copy.copy(self.option) args, namespace=copy.copy(self.option)
) )
self._validate_plugins() self._validate_plugins()
self._validate_keys()
if self.known_args_namespace.confcutdir is None and self.inifile: if self.known_args_namespace.confcutdir is None and self.inifile:
confcutdir = py.path.local(self.inifile).dirname confcutdir = py.path.local(self.inifile).dirname
self.known_args_namespace.confcutdir = confcutdir self.known_args_namespace.confcutdir = confcutdir
@ -1077,6 +1076,7 @@ class Config:
) )
else: else:
raise raise
self._validate_keys()
def _checkversion(self): def _checkversion(self):
import pytest import pytest

View File

@ -203,6 +203,15 @@ class TestParseIni:
""" """
[pytest] [pytest]
minversion = 5.0.0 minversion = 5.0.0
""",
[],
[],
"",
),
(
"""
[pytest]
conftest_ini_key = 1
""", """,
[], [],
[], [],
@ -213,16 +222,25 @@ class TestParseIni:
def test_invalid_ini_keys( def test_invalid_ini_keys(
self, testdir, ini_file_text, invalid_keys, stderr_output, exception_text 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)) testdir.tmpdir.join("pytest.ini").write(textwrap.dedent(ini_file_text))
config = testdir.parseconfig() config = testdir.parseconfig()
assert sorted(config._get_unknown_ini_keys()) == sorted(invalid_keys) assert sorted(config._get_unknown_ini_keys()) == sorted(invalid_keys)
result = testdir.runpytest() result = testdir.runpytest()
result.stderr.fnmatch_lines(stderr_output) result.stderr.fnmatch_lines(stderr_output)
if stderr_output: if exception_text:
with pytest.raises(pytest.fail.Exception, match=exception_text): with pytest.raises(pytest.fail.Exception, match=exception_text):
testdir.runpytest("--strict-config") testdir.runpytest("--strict-config")
else:
testdir.runpytest("--strict-config")
@pytest.mark.parametrize( @pytest.mark.parametrize(
"ini_file_text, exception_text", "ini_file_text, exception_text",