Skip to content

Commit 5eea6ed

Browse files
committed
Replace 'assert False' with pytest.fail()
1 parent 556dd1e commit 5eea6ed

File tree

7 files changed

+13
-11
lines changed

7 files changed

+13
-11
lines changed

Tests/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def assert_image_equal(a, b, msg=None):
9595
except Exception:
9696
pass
9797

98-
assert False, msg or "got different content"
98+
pytest.fail(msg or "got different content")
9999

100100

101101
def assert_image_equal_tofile(a, filename, msg=None, mode=None):

Tests/test_file_iptc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import sys
22
from io import BytesIO, StringIO
33

4+
import pytest
5+
46
from PIL import Image, IptcImagePlugin
57

68
from .helper import hopper
@@ -44,7 +46,7 @@ def test_getiptcinfo_fotostation():
4446
for tag in iptc.keys():
4547
if tag[0] == 240:
4648
return
47-
assert False, "FotoStation tag not found"
49+
pytest.fail("FotoStation tag not found")
4850

4951

5052
def test_getiptcinfo_zero_padding():

Tests/test_file_jpeg2k.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def test_plt_marker():
416416
while True:
417417
marker = out.read(2)
418418
if not marker:
419-
assert False, "End of stream without PLT"
419+
pytest.fail("End of stream without PLT")
420420

421421
jp2_boxid = _binary.i16be(marker)
422422
if jp2_boxid == 0xFF4F:
@@ -426,7 +426,7 @@ def test_plt_marker():
426426
# PLT
427427
return
428428
elif jp2_boxid == 0xFF93:
429-
assert False, "SOD without finding PLT first"
429+
pytest.fail("SOD without finding PLT first")
430430

431431
hdr = out.read(2)
432432
length = _binary.i16be(hdr)

Tests/test_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ def test_overrun(self, path):
999999
with Image.open(os.path.join("Tests/images", path)) as im:
10001000
try:
10011001
im.load()
1002-
assert False
1002+
pytest.fail()
10031003
except OSError as e:
10041004
buffer_overrun = str(e) == "buffer overrun when reading image file"
10051005
truncated = "image file is truncated" in str(e)
@@ -1010,7 +1010,7 @@ def test_fli_overrun2(self):
10101010
with Image.open("Tests/images/fli_overrun2.bin") as im:
10111011
try:
10121012
im.seek(1)
1013-
assert False
1013+
pytest.fail()
10141014
except OSError as e:
10151015
assert str(e) == "buffer overrun when reading image file"
10161016

Tests/test_image_resize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_reducing_gap_1(self, gradients_image, box, epsilon):
195195
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=1.0
196196
)
197197

198-
with pytest.raises(AssertionError):
198+
with pytest.raises(pytest.fail.Exception):
199199
assert_image_equal(ref, im)
200200

201201
assert_image_similar(ref, im, epsilon)
@@ -210,7 +210,7 @@ def test_reducing_gap_2(self, gradients_image, box, epsilon):
210210
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=2.0
211211
)
212212

213-
with pytest.raises(AssertionError):
213+
with pytest.raises(pytest.fail.Exception):
214214
assert_image_equal(ref, im)
215215

216216
assert_image_similar(ref, im, epsilon)
@@ -225,7 +225,7 @@ def test_reducing_gap_3(self, gradients_image, box, epsilon):
225225
(52, 34), Image.Resampling.BICUBIC, box=box, reducing_gap=3.0
226226
)
227227

228-
with pytest.raises(AssertionError):
228+
with pytest.raises(pytest.fail.Exception):
229229
assert_image_equal(ref, im)
230230

231231
assert_image_similar(ref, im, epsilon)

Tests/test_image_thumbnail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def test_reducing_gap_values():
147147

148148
ref = hopper()
149149
ref.thumbnail((18, 18), Image.Resampling.BICUBIC, reducing_gap=None)
150-
with pytest.raises(AssertionError):
150+
with pytest.raises(pytest.fail.Exception):
151151
assert_image_equal(ref, im)
152152

153153
assert_image_similar(ref, im, 3.5)

Tests/test_imageshow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_ipythonviewer():
8585
test_viewer = viewer
8686
break
8787
else:
88-
assert False
88+
pytest.fail()
8989

9090
im = hopper()
9191
assert test_viewer.show(im) == 1

0 commit comments

Comments
 (0)