Skip to content

Commit b1d3f5a

Browse files
living180DanielNoord
authored andcommitted
Add test for ModuleNotFoundError fix
Refs #7938
1 parent 27667f5 commit b1d3f5a

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from importlib import import_module
2+
3+
from pylint.checkers import BaseChecker
4+
from pylint.lint.pylinter import PyLinter
5+
6+
7+
class ImportingChecker(BaseChecker):
8+
options = (
9+
(
10+
"settings-module",
11+
{
12+
"default": "settings",
13+
"type": "string",
14+
"metavar": "<settings module>"
15+
},
16+
),
17+
)
18+
19+
msgs = {
20+
"E9999": (
21+
"Importing checker error message",
22+
"importing-checker-error",
23+
"Importing checker error message",
24+
),
25+
}
26+
27+
def open(self) -> None:
28+
import_module(self.linter.config.settings_module)
29+
30+
31+
def register(linter: "PyLinter") -> None:
32+
linter.register_checker(ImportingChecker(linter))

tests/regrtest_data/settings_project/models.py

Whitespace-only changes.

tests/regrtest_data/settings_project/settings.py

Whitespace-only changes.

tests/test_self.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,19 @@ def test_modify_sys_path() -> None:
869869
modify_sys_path()
870870
assert sys.path == paths[1:]
871871

872+
@staticmethod
873+
def test_plugin_that_imports_from_open() -> None:
874+
"""Test that a plugin that imports a source file from a checker open()
875+
function (ala pylint_django) does not raise an exception."""
876+
with _test_sys_path():
877+
# Enable --load-plugins=importing_plugin
878+
sys.path.append(join(HERE, "regrtest_data", "importing_plugin"))
879+
with _test_cwd(join(HERE, "regrtest_data", "settings_project")):
880+
Run(
881+
["--load-plugins=importing_plugin", "models.py"],
882+
exit=False,
883+
)
884+
872885
@pytest.mark.parametrize(
873886
"args",
874887
[

0 commit comments

Comments
 (0)