Skip to content

Add regression test for #3651 #7117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/lint/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,38 @@ def test_recursive_ignore(ignore_parameter, ignore_parameter_value) -> None:
assert module in linted_file_paths


def test_relative_imports(initialized_linter: PyLinter) -> None:
"""Regression test for https://github.com/PyCQA/pylint/issues/3651"""
linter = initialized_linter
with tempdir() as tmpdir:
create_files(["x/y/__init__.py", "x/y/one.py", "x/y/two.py"], tmpdir)
with open("x/y/__init__.py", "w", encoding="utf-8") as f:
f.write(
"""
\"\"\"Module x.y\"\"\"
from .one import ONE
from .two import TWO
"""
)
with open("x/y/one.py", "w", encoding="utf-8") as f:
f.write(
"""
\"\"\"Module x.y.one\"\"\"
ONE = 1
"""
)
with open("x/y/two.py", "w", encoding="utf-8") as f:
f.write(
"""
\"\"\"Module x.y.two\"\"\"
from .one import ONE
TWO = ONE + ONE
"""
)
linter.check(["x/y"])
assert not linter.stats.by_msg


def test_import_sibling_module_from_namespace(initialized_linter: PyLinter) -> None:
"""If the parent directory above `namespace` is on sys.path, ensure that
modules under `namespace` can import each other without raising `import-error`."""
Expand Down