summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-10-22 23:46:36 +0200
committerGitHub <noreply@github.com>2021-10-22 23:46:36 +0200
commit772b3dcc0b0770a843653783e5c93b4256e5ec6f (patch)
tree640e0ba18bf2ca099b77ddd337a8ff37b4214d3e
parent259f7a381d19bdbfaa84343825e0638323aed55f (diff)
downloadpylint-git-772b3dcc0b0770a843653783e5c93b4256e5ec6f.tar.gz
Fix test decorator for `PyLinter` options (#5195)
-rw-r--r--pylint/testutils/decorator.py23
-rw-r--r--tests/testutils/dummy_checker.py0
2 files changed, 18 insertions, 5 deletions
diff --git a/pylint/testutils/decorator.py b/pylint/testutils/decorator.py
index d635c7f3c..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()),
- )
+ 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
--- /dev/null
+++ b/tests/testutils/dummy_checker.py