|
24 | 24 | import pylint.lint.parallel |
25 | 25 | from pylint.checkers import BaseRawFileChecker |
26 | 26 | from pylint.checkers.imports import ImportsChecker |
| 27 | +from pylint.config.config_initialization import _config_initialization |
27 | 28 | from pylint.lint import PyLinter, augmented_sys_path |
28 | 29 | from pylint.lint.parallel import _worker_check_single_file as worker_check_single_file |
29 | 30 | from pylint.lint.parallel import _worker_initialize as worker_initialize |
@@ -217,6 +218,42 @@ def test_worker_initialize_pickling(self) -> None: |
217 | 218 | ) as executor: |
218 | 219 | executor.map(print, [1, 2]) |
219 | 220 |
|
| 221 | + def test_worker_initialize_custom_plugins(self) -> None: |
| 222 | + """Test plugins are initialized (only once) and messages are set to |
| 223 | + enabled and disabled correctly, after the worker linter is initialized. |
| 224 | + """ |
| 225 | + linter = PyLinter(reporter=Reporter()) |
| 226 | + linter.load_default_plugins() |
| 227 | + config_data = { |
| 228 | + "load-plugins": "pylint.extensions.code_style,pylint.extensions.typing", |
| 229 | + } |
| 230 | + config_args = [ |
| 231 | + "--enable=consider-using-augmented-assign", |
| 232 | + "--disable=consider-alternative-union-syntax", |
| 233 | + ] |
| 234 | + with patch( |
| 235 | + "pylint.config.config_file_parser._ConfigurationFileParser.parse_config_file", |
| 236 | + return_value=(config_data, config_args), |
| 237 | + ): |
| 238 | + _config_initialization(linter, []) |
| 239 | + assert len(linter._checkers["code_style"]) == 1 |
| 240 | + assert len(linter._checkers["typing"]) == 1 |
| 241 | + assert linter.is_message_enabled("consider-using-augmented-assign") is True |
| 242 | + assert ( # default disabled |
| 243 | + linter.is_message_enabled("prefer-typing-namedtuple") is False |
| 244 | + ) |
| 245 | + assert linter.is_message_enabled("consider-alternative-union-syntax") is False |
| 246 | + worker_initialize(linter=dill.dumps(linter)) |
| 247 | + worker_linter = pylint.lint.parallel._worker_linter |
| 248 | + assert isinstance(worker_linter, PyLinter) |
| 249 | + assert len(worker_linter._checkers["code_style"]) == 1 |
| 250 | + assert len(worker_linter._checkers["typing"]) == 1 |
| 251 | + assert linter.is_message_enabled("consider-using-augmented-assign") is True |
| 252 | + assert ( # default disabled |
| 253 | + linter.is_message_enabled("prefer-typing-namedtuple") is False |
| 254 | + ) |
| 255 | + assert linter.is_message_enabled("consider-alternative-union-syntax") is False |
| 256 | + |
220 | 257 | def test_worker_check_single_file_uninitialised(self) -> None: |
221 | 258 | pylint.lint.parallel._worker_linter = None |
222 | 259 | with pytest.raises( # Objects that do not match the linter interface will fail |
|
0 commit comments