Skip to content

Commit

Permalink
Add test for ModuleNotFoundError fix (pylint-dev#7938)
Browse files Browse the repository at this point in the history
  • Loading branch information
living180 committed Dec 15, 2022
1 parent 1cc95a5 commit 9a87500
Show file tree
Hide file tree
Showing 4 changed files with 49 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.
17 changes: 17 additions & 0 deletions tests/test_self.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,23 @@ 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."""

project_path = join(HERE, "regrtest_data", "settings_project")
plugin_path = join(HERE, "regrtest_data", "importing_plugin")
# Enable --load-plugins=importing_plugin
sys.path.append(plugin_path)
with _test_cwd():
os.chdir(project_path)
Run(
["--load-plugins=importing_plugin", "models.py"],
exit=False,
)
sys.path.remove(plugin_path)

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

0 comments on commit 9a87500

Please sign in to comment.