summaryrefslogtreecommitdiff
path: root/tests/checkers
diff options
context:
space:
mode:
authorDave Bunten <ekgto445@gmail.com>2023-01-24 00:46:23 -0700
committerGitHub <noreply@github.com>2023-01-24 08:46:23 +0100
commitbf39dbd8381041963278fae3f9eb216011024bee (patch)
tree9e4568f264f7ff25d86c1a30d2db46087e1ef62d /tests/checkers
parent911a65950ecc48d383569e04eecff574bbe862e8 (diff)
downloadpylint-git-bf39dbd8381041963278fae3f9eb216011024bee.tar.gz
Add test for existing preferred-modules functionality (#8093)
Co-authored-by: Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>
Diffstat (limited to 'tests/checkers')
-rw-r--r--tests/checkers/unittest_imports.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/checkers/unittest_imports.py b/tests/checkers/unittest_imports.py
index 8be4d63ff..ed5c13805 100644
--- a/tests/checkers/unittest_imports.py
+++ b/tests/checkers/unittest_imports.py
@@ -114,3 +114,26 @@ class TestImportsChecker(CheckerTestCase):
)
with self.assertAddsMessages(msg):
self.checker.visit_importfrom(import_from)
+
+ @staticmethod
+ def test_preferred_module(capsys: CaptureFixture[str]) -> None:
+ """
+ Tests preferred-module configuration option
+ """
+ # test preferred-modules case with base module import
+ Run(
+ [
+ f"{os.path.join(REGR_DATA, 'preferred_module')}",
+ "-d all",
+ "-e preferred-module",
+ # prefer sys instead of os (for triggering test)
+ "--preferred-modules=os:sys",
+ ],
+ exit=False,
+ )
+ output, errors = capsys.readouterr()
+
+ # assert that we saw preferred-modules triggered
+ assert "Prefer importing 'sys' instead of 'os'" in output
+ # assert there were no errors
+ assert len(errors) == 0