Skip to content

Commit 772b3dc

Browse files
authored
Fix test decorator for PyLinter options (#5195)
1 parent 259f7a3 commit 772b3dc

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pylint/testutils/decorator.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,24 @@ def _forward(self, *args, **test_function_kwargs):
2424
except optparse.OptionError:
2525
# Check if option is one of the base options of the PyLinter class
2626
for key, value in kwargs.items():
27-
self.checker.set_option(
28-
key.replace("_", "-"),
29-
value,
30-
optdict=dict(PyLinter.make_options()),
31-
)
27+
try:
28+
self.checker.set_option(
29+
key.replace("_", "-"),
30+
value,
31+
optdict=dict(PyLinter.make_options())[
32+
key.replace("_", "-")
33+
],
34+
)
35+
except KeyError:
36+
# pylint: disable-next=fixme
37+
# TODO: Find good way to double load checkers in unittests
38+
# When options are used by multiple checkers we need to load both of them
39+
# to be able to get an optdict
40+
self.checker.set_option(
41+
key.replace("_", "-"),
42+
value,
43+
optdict={},
44+
)
3245
if isinstance(self, CheckerTestCase):
3346
# reopen checker in case, it may be interested in configuration change
3447
self.checker.open()

tests/testutils/dummy_checker.py

Whitespace-only changes.

0 commit comments

Comments
 (0)