Skip to content

Commit 2ee4226

Browse files
committed
Add test
1 parent dd527a6 commit 2ee4226

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lib/test/test_lazy_import/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,22 @@ def test_lazy_import_type_attributes_accessible(self):
277277
proc = assert_python_ok("-c", code)
278278
self.assertIn(b"<built-in method resolve of lazy_import object at", proc.out)
279279

280+
@support.requires_subprocess()
281+
def test_lazy_import_type_attribute_error_message(self):
282+
"""Check that LazyImportType attribute error message is helpful."""
283+
code = textwrap.dedent(f"""
284+
lazy import asyncio
285+
try:
286+
globals()["asyncio"].Task
287+
except AttributeError as exc:
288+
assert str(exc) == (
289+
"cannot access attribute 'Task' "
290+
"on unresolved lazy import 'asyncio'"
291+
), repr(str(exc))
292+
else:
293+
assert False, 'AttributeError is not raised'
294+
""")
295+
assert_python_ok("-c", code)
280296

281297
class SyntaxRestrictionTests(LazyImportTestCase):
282298
"""Tests for syntax restrictions on lazy imports."""

0 commit comments

Comments
 (0)