Use monkeypatch

This commit is contained in:
Andrew Murray 2024-05-17 08:44:04 +10:00
parent 2a703a2d4c
commit 7554e2cfbf

View File

@ -116,16 +116,14 @@ class TestImage:
assert im.mode == "RGB" assert im.mode == "RGB"
assert im.size == (128, 128) assert im.size == (128, 128)
def test_open_verbose_failure(self) -> None: def test_open_verbose_failure(self, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(Image, "WARN_POSSIBLE_FORMATS", True)
im = io.BytesIO(b"") im = io.BytesIO(b"")
Image.WARN_POSSIBLE_FORMATS = True with pytest.warns(UserWarning):
try: with pytest.raises(UnidentifiedImageError):
with pytest.warns(UserWarning): with Image.open(im):
with pytest.raises(UnidentifiedImageError): pass
with Image.open(im):
pass
finally:
Image.WARN_POSSIBLE_FORMATS = False
def test_width_height(self) -> None: def test_width_height(self) -> None:
im = Image.new("RGB", (1, 2)) im = Image.new("RGB", (1, 2))