From 43f00e040903e42032e445aaf6ef9c7a9fb028d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 21 Oct 2021 23:50:59 +0200 Subject: Fix decorator for when option is not from ``PyLinter`` --- pylint/testutils/decorator.py | 23 ++++++++++++++++++----- tests/testutils/dummy_checker.py | 0 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 tests/testutils/dummy_checker.py diff --git a/pylint/testutils/decorator.py b/pylint/testutils/decorator.py index eaf72a62a..87fbd7afa 100644 --- a/pylint/testutils/decorator.py +++ b/pylint/testutils/decorator.py @@ -24,11 +24,24 @@ def set_config(**kwargs): except optparse.OptionError: # Check if option is one of the base options of the PyLinter class for key, value in kwargs.items(): - self.checker.set_option( - key.replace("_", "-"), - value, - optdict=dict(PyLinter.make_options())[key.replace("_", "-")], - ) + try: + self.checker.set_option( + key.replace("_", "-"), + value, + optdict=dict(PyLinter.make_options())[ + key.replace("_", "-") + ], + ) + except KeyError: + # pylint: disable-next=fixme + # TODO: Find good way to double load checkers in unittests + # When options are used by multiple checkers we need to load both of them + # to be able to get an optdict + self.checker.set_option( + key.replace("_", "-"), + value, + optdict={}, + ) if isinstance(self, CheckerTestCase): # reopen checker in case, it may be interested in configuration change self.checker.open() diff --git a/tests/testutils/dummy_checker.py b/tests/testutils/dummy_checker.py new file mode 100644 index 000000000..e69de29bb -- cgit v1.2.1