From 4cc4ebf3c9f79eb9d7484c763b11dea3ddff4b82 Mon Sep 17 00:00:00 2001 From: Gleb Nikonorov Date: Thu, 18 Jun 2020 11:58:41 -0400 Subject: [PATCH] Don't treat ini keys defined in conftest.py as invalid (#7384) --- src/_pytest/config/__init__.py | 2 +- testing/test_config.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 4ff6ce707..31b73a2c9 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -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 diff --git a/testing/test_config.py b/testing/test_config.py index d59d641f6..c9eea7a16 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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",