|
11 | 11 |
|
12 | 12 | from pylint.checkers import imports |
13 | 13 | from pylint.interfaces import UNDEFINED |
| 14 | +from pylint.lint import augmented_sys_path, discover_package_path |
14 | 15 | from pylint.testutils import CheckerTestCase, MessageTest |
15 | 16 | from pylint.testutils._run import _Run as Run |
16 | 17 |
|
@@ -92,28 +93,33 @@ def test_relative_beyond_top_level_four(capsys: CaptureFixture[str]) -> None: |
92 | 93 | assert errors == "" |
93 | 94 |
|
94 | 95 | def test_wildcard_import_init(self) -> None: |
95 | | - module = astroid.MANAGER.ast_from_module_name("init_wildcard", REGR_DATA) |
96 | | - import_from = module.body[0] |
| 96 | + context_file = os.path.join(REGR_DATA, "dummy_wildcard.py") |
97 | 97 |
|
98 | | - with self.assertNoMessages(): |
99 | | - self.checker.visit_importfrom(import_from) |
| 98 | + with augmented_sys_path([discover_package_path(context_file, [])]): |
| 99 | + module = astroid.MANAGER.ast_from_module_name("init_wildcard", context_file) |
| 100 | + import_from = module.body[0] |
| 101 | + |
| 102 | + with self.assertNoMessages(): |
| 103 | + self.checker.visit_importfrom(import_from) |
100 | 104 |
|
101 | 105 | def test_wildcard_import_non_init(self) -> None: |
102 | | - module = astroid.MANAGER.ast_from_module_name("wildcard", REGR_DATA) |
103 | | - import_from = module.body[0] |
| 106 | + context_file = os.path.join(REGR_DATA, "dummy_wildcard.py") |
104 | 107 |
|
105 | | - msg = MessageTest( |
106 | | - msg_id="wildcard-import", |
107 | | - node=import_from, |
108 | | - args="empty", |
109 | | - confidence=UNDEFINED, |
110 | | - line=1, |
111 | | - col_offset=0, |
112 | | - end_line=1, |
113 | | - end_col_offset=19, |
114 | | - ) |
115 | | - with self.assertAddsMessages(msg): |
116 | | - self.checker.visit_importfrom(import_from) |
| 108 | + with augmented_sys_path([discover_package_path(context_file, [])]): |
| 109 | + module = astroid.MANAGER.ast_from_module_name("wildcard", context_file) |
| 110 | + import_from = module.body[0] |
| 111 | + msg = MessageTest( |
| 112 | + msg_id="wildcard-import", |
| 113 | + node=import_from, |
| 114 | + args="empty", |
| 115 | + confidence=UNDEFINED, |
| 116 | + line=1, |
| 117 | + col_offset=0, |
| 118 | + end_line=1, |
| 119 | + end_col_offset=19, |
| 120 | + ) |
| 121 | + with self.assertAddsMessages(msg): |
| 122 | + self.checker.visit_importfrom(import_from) |
117 | 123 |
|
118 | 124 | @staticmethod |
119 | 125 | def test_preferred_module(capsys: CaptureFixture[str]) -> None: |
|
0 commit comments