Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 60837e1

Browse files
committedJul 31, 2022
Add regression test for #3651
1 parent 5d5f5f7 commit 60837e1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
 

‎tests/lint/unittest_lint.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
)
4040
from pylint.exceptions import InvalidMessageError
4141
from pylint.lint import PyLinter
42+
from pylint.lint.pylinter import MANAGER
4243
from pylint.lint.utils import fix_import_path
4344
from pylint.message import Message
4445
from pylint.reporters import text
@@ -914,6 +915,39 @@ def test_recursive_ignore(ignore_parameter, ignore_parameter_value) -> None:
914915
assert module in linted_file_paths
915916

916917

918+
def test_relative_imports(initialized_linter: PyLinter) -> None:
919+
"""Regression test for https://github.com/PyCQA/pylint/issues/3651"""
920+
linter = initialized_linter
921+
MANAGER.clear_cache() # Essential to reproduce the failure
922+
with tempdir() as tmpdir:
923+
create_files(["x/y/__init__.py", "x/y/one.py", "x/y/two.py"], tmpdir)
924+
with open("x/y/__init__.py", "w", encoding="utf-8") as f:
925+
f.write(
926+
"""
927+
\"\"\"Module x.y\"\"\"
928+
from .one import ONE
929+
from .two import TWO
930+
"""
931+
)
932+
with open("x/y/one.py", "w", encoding="utf-8") as f:
933+
f.write(
934+
"""
935+
\"\"\"Module x.y.one\"\"\"
936+
ONE = 1
937+
"""
938+
)
939+
with open("x/y/two.py", "w", encoding="utf-8") as f:
940+
f.write(
941+
"""
942+
\"\"\"Module x.y.two\"\"\"
943+
from .one import ONE
944+
TWO = ONE + ONE
945+
"""
946+
)
947+
linter.check(["x"])
948+
assert not linter.stats.by_msg
949+
950+
917951
def test_import_sibling_module_from_namespace(initialized_linter: PyLinter) -> None:
918952
"""If the parent directory above `namespace` is on sys.path, ensure that
919953
modules under `namespace` can import each other without raising `import-error`."""

0 commit comments

Comments
 (0)
Please sign in to comment.