Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Lib/bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io
import os

import _bz2; _bz2 # Force the eager import of _bz2
from _bz2 import BZ2Compressor, BZ2Decompressor


Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,20 @@ def test_newline(self):
self.assertEqual(f.readlines(), [text])


class TestMissingModuleImport(unittest.TestCase):
# Test that module import fails if _bz2 is not available
# See: https://github.com/python/cpython/issues/150167
@support.thread_unsafe("Modifies global import state")
def test_under_lazy_all(self):
import_state = sys.get_lazy_imports()
try:
sys.set_lazy_imports("all")
with self.assertRaises(ImportError):
import_helper.import_fresh_module("bz2", blocked=("_bz2",))
finally:
sys.set_lazy_imports(import_state)


def tearDownModule():
support.reap_children()

Expand Down
Loading