aboutsummaryrefslogtreecommitdiff
path: root/pylint/testutils/decorator.py
diff options
context:
space:
mode:
Diffstat (limited to 'pylint/testutils/decorator.py')
-rw-r--r--pylint/testutils/decorator.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/pylint/testutils/decorator.py b/pylint/testutils/decorator.py
new file mode 100644
index 000000000..44d186d1e
--- /dev/null
+++ b/pylint/testutils/decorator.py
@@ -0,0 +1,28 @@
+# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
+
+import functools
+
+from pylint.testutils.checker_test_case import CheckerTestCase
+
+
+def set_config(**kwargs):
+ """Decorator for setting config values on a checker.
+
+ Passing the args and kwargs back to the test function itself
+ allows this decorator to be used on parametrized test cases.
+ """
+
+ def _wrapper(fun):
+ @functools.wraps(fun)
+ def _forward(self, *args, **test_function_kwargs):
+ for key, value in kwargs.items():
+ setattr(self.checker.config, key, value)
+ if isinstance(self, CheckerTestCase):
+ # reopen checker in case, it may be interested in configuration change
+ self.checker.open()
+ fun(self, *args, **test_function_kwargs)
+
+ return _forward
+
+ return _wrapper