Skip to content

Commit

Permalink
Add test for ModuleNotFoundError fix
Browse files Browse the repository at this point in the history
Refs #7938
  • Loading branch information
living180 authored and DanielNoord committed Dec 15, 2022
1 parent 27667f5 commit b1d3f5a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/regrtest_data/importing_plugin/importing_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from importlib import import_module

from pylint.checkers import BaseChecker
from pylint.lint.pylinter import PyLinter


class ImportingChecker(BaseChecker):
options = (
(
"settings-module",
{
"default": "settings",
"type": "string",
"metavar": "<settings module>"
},
),
)

msgs = {
"E9999": (
"Importing checker error message",
"importing-checker-error",
"Importing checker error message",
),
}

def open(self) -> None:
import_module(self.linter.config.settings_module)


def register(linter: "PyLinter") -> None:
linter.register_checker(ImportingChecker(linter))
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,19 @@ def test_modify_sys_path() -> None:
modify_sys_path()
assert sys.path == paths[1:]

@staticmethod
def test_plugin_that_imports_from_open() -> None:
"""Test that a plugin that imports a source file from a checker open()
function (ala pylint_django) does not raise an exception."""
with _test_sys_path():
# Enable --load-plugins=importing_plugin
sys.path.append(join(HERE, "regrtest_data", "importing_plugin"))
with _test_cwd(join(HERE, "regrtest_data", "settings_project")):
Run(
["--load-plugins=importing_plugin", "models.py"],
exit=False,
)

@pytest.mark.parametrize(
"args",
[
Expand Down

0 comments on commit b1d3f5a

Please sign in to comment.