|
39 | 39 | )
|
40 | 40 | from pylint.exceptions import InvalidMessageError
|
41 | 41 | from pylint.lint import PyLinter
|
| 42 | +from pylint.lint.pylinter import MANAGER |
42 | 43 | from pylint.lint.utils import fix_import_path
|
43 | 44 | from pylint.message import Message
|
44 | 45 | from pylint.reporters import text
|
@@ -914,6 +915,39 @@ def test_recursive_ignore(ignore_parameter, ignore_parameter_value) -> None:
|
914 | 915 | assert module in linted_file_paths
|
915 | 916 |
|
916 | 917 |
|
| 918 | +def test_relative_imports(initialized_linter: PyLinter) -> None: |
| 919 | + """Regression test for https://github.com/PyCQA/pylint/issues/3651""" |
| 920 | + linter = initialized_linter |
| 921 | + MANAGER.clear_cache() # Essential to reproduce the failure |
| 922 | + with tempdir() as tmpdir: |
| 923 | + create_files(["x/y/__init__.py", "x/y/one.py", "x/y/two.py"], tmpdir) |
| 924 | + with open("x/y/__init__.py", "w", encoding="utf-8") as f: |
| 925 | + f.write( |
| 926 | + """ |
| 927 | +\"\"\"Module x.y\"\"\" |
| 928 | +from .one import ONE |
| 929 | +from .two import TWO |
| 930 | +""" |
| 931 | + ) |
| 932 | + with open("x/y/one.py", "w", encoding="utf-8") as f: |
| 933 | + f.write( |
| 934 | + """ |
| 935 | +\"\"\"Module x.y.one\"\"\" |
| 936 | +ONE = 1 |
| 937 | +""" |
| 938 | + ) |
| 939 | + with open("x/y/two.py", "w", encoding="utf-8") as f: |
| 940 | + f.write( |
| 941 | + """ |
| 942 | +\"\"\"Module x.y.two\"\"\" |
| 943 | +from .one import ONE |
| 944 | +TWO = ONE + ONE |
| 945 | +""" |
| 946 | + ) |
| 947 | + linter.check(["x"]) |
| 948 | + assert not linter.stats.by_msg |
| 949 | + |
| 950 | + |
917 | 951 | def test_import_sibling_module_from_namespace(initialized_linter: PyLinter) -> None:
|
918 | 952 | """If the parent directory above `namespace` is on sys.path, ensure that
|
919 | 953 | modules under `namespace` can import each other without raising `import-error`."""
|
|
0 commit comments