Skip to content

Commit

Permalink
Add regression test for #6538 (#6553)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
jacobtylerwalls and Pierre-Sassoulas committed May 9, 2022
1 parent fa183c7 commit 63a9124
Showing 1 changed file with 22 additions and 0 deletions.
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

0 comments on commit 63a9124

Please sign in to comment.