Skip to content

Commit 04a8f12

Browse files
committed
Add a test for import failure under lazy_imports=all
1 parent 392ad7e commit 04a8f12

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/test/test_bz2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,20 @@ def test_newline(self):
12221222
self.assertEqual(f.readlines(), [text])
12231223

12241224

1225+
class TestMissingModuleImport(unittest.TestCase):
1226+
# Test that module import fails if _bz2 is not available
1227+
# See: https://github.com/python/cpython/issues/150167
1228+
@support.thread_unsafe("Modifies global import state")
1229+
def test_under_lazy_all(self):
1230+
import_state = sys.get_lazy_imports()
1231+
try:
1232+
sys.set_lazy_imports("all")
1233+
with self.assertRaises(ImportError):
1234+
import_helper.import_fresh_module("bz2", blocked=("_bz2",))
1235+
finally:
1236+
sys.set_lazy_imports(import_state)
1237+
1238+
12251239
def tearDownModule():
12261240
support.reap_children()
12271241

0 commit comments

Comments
 (0)