From 60837e1b985246e67e6cf363e9729ec76b3e3ac9 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 3 Jul 2022 10:37:37 -0400 Subject: [PATCH 1/2] Add regression test for #3651 --- tests/lint/unittest_lint.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index c9407bbc64..263f350ca1 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -39,6 +39,7 @@ ) from pylint.exceptions import InvalidMessageError from pylint.lint import PyLinter +from pylint.lint.pylinter import MANAGER from pylint.lint.utils import fix_import_path from pylint.message import Message from pylint.reporters import text @@ -914,6 +915,39 @@ 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 + MANAGER.clear_cache() # Essential to reproduce the failure + 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"]) + 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`.""" From c7f9d85afb183958c9fa5e855904b172b11c3777 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sun, 21 Aug 2022 10:33:27 -0400 Subject: [PATCH 2/2] Update test --- tests/lint/unittest_lint.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 263f350ca1..31932e14fc 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -39,7 +39,6 @@ ) from pylint.exceptions import InvalidMessageError from pylint.lint import PyLinter -from pylint.lint.pylinter import MANAGER from pylint.lint.utils import fix_import_path from pylint.message import Message from pylint.reporters import text @@ -918,7 +917,6 @@ def test_recursive_ignore(ignore_parameter, ignore_parameter_value) -> None: def test_relative_imports(initialized_linter: PyLinter) -> None: """Regression test for https://github.com/PyCQA/pylint/issues/3651""" linter = initialized_linter - MANAGER.clear_cache() # Essential to reproduce the failure 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: @@ -944,7 +942,7 @@ def test_relative_imports(initialized_linter: PyLinter) -> None: TWO = ONE + ONE """ ) - linter.check(["x"]) + linter.check(["x/y"]) assert not linter.stats.by_msg