Skip to content

Commit c0fe1c5

Browse files
authored
Fix two incorrect/broken tests in tests/checkers/unittest_imports.py (#9911)
1 parent 56c64e5 commit c0fe1c5

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

tests/checkers/unittest_imports.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from pylint.checkers import imports
1313
from pylint.interfaces import UNDEFINED
14+
from pylint.lint import augmented_sys_path, discover_package_path
1415
from pylint.testutils import CheckerTestCase, MessageTest
1516
from pylint.testutils._run import _Run as Run
1617

@@ -92,28 +93,33 @@ def test_relative_beyond_top_level_four(capsys: CaptureFixture[str]) -> None:
9293
assert errors == ""
9394

9495
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")
9797

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)
100104

101105
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")
104107

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)
117123

118124
@staticmethod
119125
def test_preferred_module(capsys: CaptureFixture[str]) -> None:

tests/regrtest_data/dummy_wildcard.py

Whitespace-only changes.

0 commit comments

Comments
 (0)