summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2022-08-21 10:42:59 -0400
committerGitHub <noreply@github.com>2022-08-21 14:42:59 +0000
commit3bfd0756d669c69f11164eab67340e9f2bc3383a (patch)
tree1b3145121bf8d747726bf79c6a3e0af6579dfa80
parent7fdf8d9ee09076515739fc997837b6c7c79a6072 (diff)
downloadpylint-git-3bfd0756d669c69f11164eab67340e9f2bc3383a.tar.gz
Add regression test for #3651 (#7117)
-rw-r--r--tests/lint/unittest_lint.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py
index 2f3a5c170..d2fa888fc 100644
--- a/tests/lint/unittest_lint.py
+++ b/tests/lint/unittest_lint.py
@@ -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`."""