Restored original state using finally

Co-authored-by: Ondrej Baranovič <nulano@nulano.eu>
This commit is contained in:
Andrew Murray 2024-01-24 08:12:06 +11:00 committed by GitHub
parent 8caae8739f
commit e2d1b2663d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,7 +35,9 @@ class TestDefaultFontLeak(TestTTypeFontLeak):
def test_leak(self): def test_leak(self):
if features.check_module("freetype2"): if features.check_module("freetype2"):
ImageFont.core = _util.DeferredError(ImportError) ImageFont.core = _util.DeferredError(ImportError)
default_font = ImageFont.load_default() try:
ImageFont.core = original_core default_font = ImageFont.load_default()
finally:
ImageFont.core = original_core
self._test_font(default_font) self._test_font(default_font)