Skip to content
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

Add regression test for #6538 #6553

Merged
merged 4 commits into from
May 9, 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
22 changes: 22 additions & 0 deletions tests/lint/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
)
from pylint.exceptions import InvalidMessageError
from pylint.lint import PyLinter
from pylint.lint.utils import fix_import_path
from pylint.message import Message
from pylint.reporters import text
from pylint.testutils import create_files
Expand Down Expand Up @@ -861,3 +862,24 @@ def test_by_module_statement_value(initialized_linter: PyLinter) -> None:
# Check that the by_module "statement" is equal to the global "statement"
# computed for that module
assert module_stats["statement"] == linter2.stats.statement


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`."""
linter = initialized_linter
with tempdir() as tmpdir:
create_files(["namespace/submodule1.py", "namespace/submodule2.py"])
second_path = Path("namespace/submodule2.py")
with open(second_path, "w", encoding="utf-8") as f:
f.write(
"""\"\"\"This module imports submodule1.\"\"\"
import submodule1
print(submodule1)
"""
)
os.chdir("namespace")
# Add the parent directory to sys.path
with fix_import_path([tmpdir]):
linter.check(["submodule2.py"])
assert not linter.stats.by_msg