From 8ac18bbecb2eb9646598b4bb1bfe429d4d26cc9d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 2 Jun 2020 16:01:47 -0300 Subject: [PATCH] Show invalid ini keys sorted Otherwise this relies on the dictionary order of `config.inicfg`, which is insertion order in py36+ but "random" order in py35. --- src/_pytest/config/__init__.py | 2 +- testing/test_config.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 5fc23716dc3..343cdd960ff 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -1074,7 +1074,7 @@ def _checkversion(self): ) def _validatekeys(self): - for key in self._get_unknown_ini_keys(): + for key in sorted(self._get_unknown_ini_keys()): message = "Unknown config ini key: {}\n".format(key) if self.known_args_namespace.strict_config: fail(message, pytrace=False) diff --git a/testing/test_config.py b/testing/test_config.py index 6a08e93f39c..c102202edd8 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -158,10 +158,10 @@ def test_confcutdir(self, testdir): """, ["unknown_ini", "another_unknown_ini"], [ - "WARNING: Unknown config ini key: unknown_ini", "WARNING: Unknown config ini key: another_unknown_ini", + "WARNING: Unknown config ini key: unknown_ini", ], - "Unknown config ini key: unknown_ini", + "Unknown config ini key: another_unknown_ini", ), ( """ @@ -200,9 +200,7 @@ def test_invalid_ini_keys( ): testdir.tmpdir.join("pytest.ini").write(textwrap.dedent(ini_file_text)) config = testdir.parseconfig() - assert config._get_unknown_ini_keys() == invalid_keys, str( - config._get_unknown_ini_keys() - ) + assert sorted(config._get_unknown_ini_keys()) == sorted(invalid_keys) result = testdir.runpytest() result.stderr.fnmatch_lines(stderr_output)