Skip to content

Commit

Permalink
Fix test to use specifically pickle-unsafe module
Browse files Browse the repository at this point in the history
The test also includes an assert to confirm the module picked is
actually unsafe, in case it is made safe in the future.
Also include docstring edits suggested by reviews.
  • Loading branch information
daogilvie committed Oct 18, 2022
1 parent 170d923 commit 1c06535
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
3 changes: 0 additions & 3 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,6 @@ def load_plugin_configuration(self) -> None:
"bad-plugin-value", args=(modname, module_or_error), line=0
)
elif hasattr(module_or_error, "load_configuration"):
# Mypy is not smart enough to realize that we only call
# this line if the object has the attr we are looking at.
# Hence the one-line type: ignore[union-attr] here.
module_or_error.load_configuration(self) # type: ignore[union-attr]
# We re-set all the dictionary values to True here to make sure the dict
# is pickle-able. This is only a problem in multiprocessing/parallel mode.
Expand Down
24 changes: 10 additions & 14 deletions tests/test_check_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import argparse
import multiprocessing
import os
import sys
from pathlib import Path

import dill
import pytest
Expand Down Expand Up @@ -233,21 +231,19 @@ def test_worker_check_single_file_no_checkers(self) -> None:
assert stats.statement == 18
assert stats.warning == 0

def test_linter_with_plugins_is_pickleable(self) -> None:
"""
The linter needs to be pickle-able in order to be passed between workers
"""
dummy_plugin_path = Path(__file__).parent / "regrtest_data" / "dummy_plugin"
dummy_plugin_path_str = str(dummy_plugin_path.absolute())
sys.path.append(dummy_plugin_path_str)
def test_linter_with_unpickleable_plugins_is_pickleable(self) -> None:
"""The linter needs to be pickle-able in order to be passed between workers"""
linter = PyLinter(reporter=Reporter())
print(linter._dynamic_plugins)
# We load an extension that we know is not pickle-safe
linter.load_plugin_modules(["pylint.extensions.overlapping_exceptions"])
with pytest.raises(KeyError):
dill.dumps(linter)
# And expect this call to make it pickle-able
linter.load_plugin_configuration()
try:
dill.dumps(linter)
except dill.PicklingError:
assert False, "Loading plugins caused an un-pickle-able linter"
finally:
sys.path.remove(dummy_plugin_path_str)
except KeyError:
assert False, "Cannot pickle linter when using non-pickleable plugin"

def test_worker_check_sequential_checker(self) -> None:
"""Same as test_worker_check_single_file_no_checkers with SequentialTestChecker."""
Expand Down

0 comments on commit 1c06535

Please sign in to comment.