diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-09-19 17:57:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-19 12:57:29 -0300 |
commit | 89305e7b091a78f6288e0a4bba32f68d2f49bd07 (patch) | |
tree | 28443c02edabaee871ee84553bab8a2561c9e91d /testing/test_config.py | |
parent | 9bfd14a443f16826dac3ecd74129e1922fe131da (diff) | |
download | pytest-89305e7b091a78f6288e0a4bba32f68d2f49bd07.tar.gz |
Improve output for missing config keys (#7572)
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
Diffstat (limited to 'testing/test_config.py')
-rw-r--r-- | testing/test_config.py | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/testing/test_config.py b/testing/test_config.py index c1c660ab0..aa84a3cf5 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -181,12 +181,12 @@ class TestParseIni: @pytest.mark.parametrize( "ini_file_text, invalid_keys, warning_output, exception_text", [ - ( + pytest.param( """ - [pytest] - unknown_ini = value1 - another_unknown_ini = value2 - """, + [pytest] + unknown_ini = value1 + another_unknown_ini = value2 + """, ["unknown_ini", "another_unknown_ini"], [ "=*= warnings summary =*=", @@ -194,48 +194,53 @@ class TestParseIni: "*PytestConfigWarning:*Unknown config option: unknown_ini", ], "Unknown config option: another_unknown_ini", + id="2-unknowns", ), - ( + pytest.param( """ - [pytest] - unknown_ini = value1 - minversion = 5.0.0 - """, + [pytest] + unknown_ini = value1 + minversion = 5.0.0 + """, ["unknown_ini"], [ "=*= warnings summary =*=", "*PytestConfigWarning:*Unknown config option: unknown_ini", ], "Unknown config option: unknown_ini", + id="1-unknown", ), - ( + pytest.param( """ - [some_other_header] - unknown_ini = value1 - [pytest] - minversion = 5.0.0 - """, + [some_other_header] + unknown_ini = value1 + [pytest] + minversion = 5.0.0 + """, [], [], "", + id="unknown-in-other-header", ), - ( + pytest.param( """ - [pytest] - minversion = 5.0.0 - """, + [pytest] + minversion = 5.0.0 + """, [], [], "", + id="no-unknowns", ), - ( + pytest.param( """ - [pytest] - conftest_ini_key = 1 - """, + [pytest] + conftest_ini_key = 1 + """, [], [], "", + id="1-known", ), ], ) @@ -247,9 +252,10 @@ class TestParseIni: """ def pytest_addoption(parser): parser.addini("conftest_ini_key", "") - """ + """ ) - testdir.tmpdir.join("pytest.ini").write(textwrap.dedent(ini_file_text)) + testdir.makepyfile("def test(): pass") + testdir.makeini(ini_file_text) config = testdir.parseconfig() assert sorted(config._get_unknown_ini_keys()) == sorted(invalid_keys) @@ -257,9 +263,13 @@ class TestParseIni: result = testdir.runpytest() result.stdout.fnmatch_lines(warning_output) + result = testdir.runpytest("--strict-config") if exception_text: - result = testdir.runpytest("--strict-config") - result.stdout.fnmatch_lines("INTERNALERROR>*" + exception_text) + result.stderr.fnmatch_lines("ERROR: " + exception_text) + assert result.ret == pytest.ExitCode.USAGE_ERROR + else: + result.stderr.no_fnmatch_line(exception_text) + assert result.ret == pytest.ExitCode.OK @pytest.mark.filterwarnings("default") def test_silence_unknown_key_warning(self, testdir: Testdir) -> None: |