diff --git a/pylint/lint.py b/pylint/lint.py index 578e847ff2..1960e544b1 100644 --- a/pylint/lint.py +++ b/pylint/lint.py @@ -1475,11 +1475,15 @@ def fix_import_path(args): """ orig = list(sys.path) changes = [] + seen = set() + cwd = os.getcwd() for arg in args: path = _get_python_path(arg) - if path not in changes: + if path not in seen and path != cwd: changes.append(path) - sys.path[:] = changes + ["."] + sys.path + seen.add(path) + + sys.path[:] = changes + sys.path try: yield finally: diff --git a/tests/unittest_lint.py b/tests/unittest_lint.py index 3252a5e437..336e05e820 100644 --- a/tests/unittest_lint.py +++ b/tests/unittest_lint.py @@ -165,7 +165,7 @@ def fake_path(): def test_no_args(fake_path): with lint.fix_import_path([]): - assert sys.path == ["."] + fake_path + assert sys.path == fake_path assert sys.path == fake_path @@ -175,7 +175,7 @@ def test_no_args(fake_path): def test_one_arg(fake_path, case): with tempdir() as chroot: create_files(["a/b/__init__.py"]) - expected = [join(chroot, "a")] + ["."] + fake_path + expected = [join(chroot, "a")] + fake_path assert sys.path == fake_path with lint.fix_import_path(case): @@ -195,7 +195,7 @@ def test_one_arg(fake_path, case): def test_two_similar_args(fake_path, case): with tempdir() as chroot: create_files(["a/b/__init__.py", "a/c/__init__.py"]) - expected = [join(chroot, "a")] + ["."] + fake_path + expected = [join(chroot, "a")] + fake_path assert sys.path == fake_path with lint.fix_import_path(case): @@ -214,14 +214,10 @@ def test_two_similar_args(fake_path, case): def test_more_args(fake_path, case): with tempdir() as chroot: create_files(["a/b/c/__init__.py", "a/d/__init__.py", "a/e/f.py"]) - expected = ( - [ - join(chroot, suffix) - for suffix in [sep.join(("a", "b")), "a", sep.join(("a", "e"))] - ] - + ["."] - + fake_path - ) + expected = [ + join(chroot, suffix) + for suffix in [sep.join(("a", "b")), "a", sep.join(("a", "e"))] + ] + fake_path assert sys.path == fake_path with lint.fix_import_path(case):