Skip to content

Commit

Permalink
Use monkeypatch
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed May 16, 2024
1 parent 2a703a2 commit 7554e2c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,14 @@ def test_open_formats(self) -> None:
assert im.mode == "RGB"
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"")
Image.WARN_POSSIBLE_FORMATS = True
try:
with pytest.warns(UserWarning):
with pytest.raises(UnidentifiedImageError):
with Image.open(im):
pass
finally:
Image.WARN_POSSIBLE_FORMATS = False
with pytest.warns(UserWarning):
with pytest.raises(UnidentifiedImageError):
with Image.open(im):
pass

def test_width_height(self) -> None:
im = Image.new("RGB", (1, 2))
Expand Down

0 comments on commit 7554e2c

Please sign in to comment.