Skip to content

Commit 60bdbaf

Browse files
Attempt to add tests.
One test added and one modified.
1 parent 173b211 commit 60bdbaf

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lib/test/test_importlib/test_lazy.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ def test_e2e(self):
9090
with test_util.import_state(meta_path=[importer]):
9191
module = importlib.import_module(importer.module_name)
9292
self.assertIsNone(importer.loaded)
93+
94+
# Check that getting __spec__ doesn't trigger the load.
95+
module.__spec__
96+
self.assertIsNone(importer.loaded)
97+
9398
# Trigger load.
9499
self.assertEqual(module.__loader__, importer)
95100
self.assertIsNotNone(importer.loaded)
@@ -224,6 +229,21 @@ def __delattr__(self, name):
224229
with self.assertRaises(AttributeError):
225230
del module.CONSTANT
226231

232+
def test_spec_passthrough(self):
233+
# Verify that a lazily loaded module can have its __spec__ retrieved without triggering
234+
# a full load. That way, importlib internal machinery will not cause a load when pulling
235+
# a lazily loaded module out of sys.modules.
236+
loader = TestingImporter()
237+
module = self.new_module(loader=loader)
238+
239+
# Access __spec__ without triggering the load.
240+
_ = module.__spec__
241+
self.assertIsNone(loader.loaded)
242+
243+
# Trigger the full load.
244+
_ = module.attr
245+
self.assertIsNotNone(loader.loaded)
246+
227247

228248
if __name__ == '__main__':
229249
unittest.main()

0 commit comments

Comments
 (0)