From 7d6043bfd3012c9212520548b37bbcecf118931b Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 12 Nov 2023 22:01:47 +0200 Subject: [PATCH] Replace 'assert False' with pytest.fail() --- Tests/helper.py | 2 +- Tests/test_file_iptc.py | 4 +++- Tests/test_file_jpeg2k.py | 4 ++-- Tests/test_image.py | 4 ++-- Tests/test_imageshow.py | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index de5468d8463..aacd9556493 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -95,7 +95,7 @@ def assert_image_equal(a, b, msg=None): except Exception: pass - assert False, msg or "got different content" + pytest.fail(msg or "got different content") def assert_image_equal_tofile(a, filename, msg=None, mode=None): diff --git a/Tests/test_file_iptc.py b/Tests/test_file_iptc.py index d2edcfc27c9..dac35a8d0e8 100644 --- a/Tests/test_file_iptc.py +++ b/Tests/test_file_iptc.py @@ -1,6 +1,8 @@ import sys from io import BytesIO, StringIO +import pytest + from PIL import Image, IptcImagePlugin from .helper import hopper @@ -44,7 +46,7 @@ def test_getiptcinfo_fotostation(): for tag in iptc.keys(): if tag[0] == 240: return - assert False, "FotoStation tag not found" + pytest.fail("FotoStation tag not found") def test_getiptcinfo_zero_padding(): diff --git a/Tests/test_file_jpeg2k.py b/Tests/test_file_jpeg2k.py index 99df26fc905..2016b3ccbe3 100644 --- a/Tests/test_file_jpeg2k.py +++ b/Tests/test_file_jpeg2k.py @@ -416,7 +416,7 @@ def test_plt_marker(): while True: marker = out.read(2) if not marker: - assert False, "End of stream without PLT" + pytest.fail("End of stream without PLT") jp2_boxid = _binary.i16be(marker) if jp2_boxid == 0xFF4F: @@ -426,7 +426,7 @@ def test_plt_marker(): # PLT return elif jp2_boxid == 0xFF93: - assert False, "SOD without finding PLT first" + pytest.fail("SOD without finding PLT first") hdr = out.read(2) length = _binary.i16be(hdr) diff --git a/Tests/test_image.py b/Tests/test_image.py index 039eb33d1ef..9efd4c4677d 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -999,7 +999,7 @@ def test_overrun(self, path): with Image.open(os.path.join("Tests/images", path)) as im: try: im.load() - assert False + pytest.fail() except OSError as e: buffer_overrun = str(e) == "buffer overrun when reading image file" truncated = "image file is truncated" in str(e) @@ -1010,7 +1010,7 @@ def test_fli_overrun2(self): with Image.open("Tests/images/fli_overrun2.bin") as im: try: im.seek(1) - assert False + pytest.fail() except OSError as e: assert str(e) == "buffer overrun when reading image file" diff --git a/Tests/test_imageshow.py b/Tests/test_imageshow.py index e54372b60de..3e73339ed3f 100644 --- a/Tests/test_imageshow.py +++ b/Tests/test_imageshow.py @@ -85,7 +85,7 @@ def test_ipythonviewer(): test_viewer = viewer break else: - assert False + pytest.fail() im = hopper() assert test_viewer.show(im) == 1