Skip to content

Commit

Permalink
Don't treat ini keys defined in conftest.py as invalid (#7384)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikonorov authored Jun 18, 2020
1 parent 88a187a commit 4cc4ebf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,6 @@ def _preparse(self, args: List[str], addopts: bool = True) -> None:
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
Expand All @@ -1077,6 +1076,7 @@ def _preparse(self, args: List[str], addopts: bool = True) -> None:
)
else:
raise
self._validate_keys()

def _checkversion(self):
import pytest
Expand Down
20 changes: 19 additions & 1 deletion testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ def test_confcutdir(self, testdir):
"""
[pytest]
minversion = 5.0.0
""",
[],
[],
"",
),
(
"""
[pytest]
conftest_ini_key = 1
""",
[],
[],
Expand All @@ -213,16 +222,25 @@ def test_confcutdir(self, testdir):
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",
Expand Down

0 comments on commit 4cc4ebf

Please sign in to comment.