Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ignoring tests when running valgrind #5150

Merged
merged 8 commits into from Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions Tests/conftest.py
@@ -1,4 +1,7 @@
import io
import warnings

import pytest


def pytest_report_header(config):
Expand All @@ -10,3 +13,19 @@ def pytest_report_header(config):
return out.getvalue()
except Exception as e:
return f"pytest_report_header failed: {e}"

radarhere marked this conversation as resolved.
Show resolved Hide resolved

def pytest_configure(config):
# We're marking some tests to ignore valgrind errors and XFAIL them.
# Ensure that the mark is defined
# even in cases where pytest-valgrind isn't installed

with warnings.catch_warnings():
warnings.simplefilter("error")
try:
getattr(pytest.mark, "valgrind_known_error")
except Exception:
config.addinivalue_line(
"markers",
"valgrind_known_error: Tests that have known issues with valgrind",
)
1 change: 1 addition & 0 deletions Tests/test_file_eps.py
Expand Up @@ -59,6 +59,7 @@ def test_invalid_file():
EpsImagePlugin.EpsImageFile(invalid_file)


@pytest.mark.valgrind_known_error(reason="Known Failing")
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
def test_cmyk():
with Image.open("Tests/images/pil_sample_cmyk.eps") as cmyk_image:
Expand Down
6 changes: 6 additions & 0 deletions Tests/test_file_jpeg.py
Expand Up @@ -114,6 +114,7 @@ def test(xdpi, ydpi=None):
assert test(100, 200) == (100, 200)
assert test(0) is None # square pixels

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_icc(self, tmp_path):
# Test ICC support
with Image.open("Tests/images/rgb.jpg") as im1:
Expand Down Expand Up @@ -153,6 +154,7 @@ def test(n):
test(ImageFile.MAXBLOCK + 1) # full buffer block plus one byte
test(ImageFile.MAXBLOCK * 4 + 3) # large block

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_large_icc_meta(self, tmp_path):
# https://github.com/python-pillow/Pillow/issues/148
# Sometimes the meta data on the icc_profile block is bigger than
Expand Down Expand Up @@ -419,6 +421,7 @@ def test_ff00_jpeg_header(self):
with Image.open(filename):
pass

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_truncated_jpeg_should_read_all_the_data(self):
filename = "Tests/images/truncated_jpeg.jpg"
ImageFile.LOAD_TRUNCATED_IMAGES = True
Expand All @@ -437,6 +440,7 @@ def test_truncated_jpeg_throws_oserror(self):
with pytest.raises(OSError):
im.load()

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_qtables(self, tmp_path):
def _n_qtables_helper(n, test_file):
with Image.open(test_file) as im:
Expand Down Expand Up @@ -720,6 +724,7 @@ def test_invalid_exif(self):
# OSError for unidentified image.
assert im.info.get("dpi") == (72, 72)

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_exif_x_resolution(self, tmp_path):
with Image.open("Tests/images/flower.jpg") as im:
exif = im.getexif()
Expand Down Expand Up @@ -750,6 +755,7 @@ def test_ifd_offset_exif(self):
# Act / Assert
assert im._getexif()[306] == "2017:03:13 23:03:09"

@pytest.mark.valgrind_known_error(reason="Backtrace in Python Core")
def test_photoshop(self):
with Image.open("Tests/images/photoshop-200dpi.jpg") as im:
assert im.info["photoshop"][0x03ED] == {
Expand Down
6 changes: 6 additions & 0 deletions Tests/test_file_libtiff.py
Expand Up @@ -185,6 +185,7 @@ def test_write_metadata(self, tmp_path):
for field in requested_fields:
assert field in reloaded, f"{field} not in metadata"

@pytest.mark.valgrind_known_error(reason="Known invalid metadata")
def test_additional_metadata(self, tmp_path):
# these should not crash. Seriously dummy data, most of it doesn't make
# any sense, so we're running up against limits where we're asking
Expand Down Expand Up @@ -814,12 +815,14 @@ def test_strip_cmyk_16l_jpeg(self):
with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 0.5)

@pytest.mark.valgrind_known_error(reason="Known Failing")
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_strip_ycbcr_jpeg_2x2_sampling(self):
infile = "Tests/images/tiff_strip_ycbcr_jpeg_2x2_sampling.tif"
with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/flower.jpg", 0.5)

@pytest.mark.valgrind_known_error(reason="Known Failing")
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_strip_ycbcr_jpeg_1x1_sampling(self):
infile = "Tests/images/tiff_strip_ycbcr_jpeg_1x1_sampling.tif"
Expand All @@ -831,12 +834,14 @@ def test_tiled_cmyk_jpeg(self):
with Image.open(infile) as im:
assert_image_similar_tofile(im, "Tests/images/pil_sample_cmyk.jpg", 0.5)

@pytest.mark.valgrind_known_error(reason="Known Failing")
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_tiled_ycbcr_jpeg_1x1_sampling(self):
infile = "Tests/images/tiff_tiled_ycbcr_jpeg_1x1_sampling.tif"
with Image.open(infile) as im:
assert_image_equal_tofile(im, "Tests/images/flower2.jpg")

@pytest.mark.valgrind_known_error(reason="Known Failing")
@pytest.mark.xfail(is_big_endian(), reason="Fails on big-endian")
def test_tiled_ycbcr_jpeg_2x2_sampling(self):
infile = "Tests/images/tiff_tiled_ycbcr_jpeg_2x2_sampling.tif"
Expand Down Expand Up @@ -864,6 +869,7 @@ def test_orientation(self):

assert_image_similar(base_im, im, 0.7)

@pytest.mark.valgrind_known_error(reason="Backtrace in Python Core")
def test_sampleformat_not_corrupted(self):
# Assert that a TIFF image with SampleFormat=UINT tag is not corrupted
# when saving to a new file.
Expand Down
1 change: 1 addition & 0 deletions Tests/test_file_pdf.py
Expand Up @@ -85,6 +85,7 @@ def test_unsupported_mode(tmp_path):
im.save(outfile)


@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_save_all(tmp_path):
# Single frame image
helper_save_as_pdf(tmp_path, "RGB", save_all=True)
Expand Down
1 change: 1 addition & 0 deletions Tests/test_file_png.py
Expand Up @@ -654,6 +654,7 @@ def test_exif_save(self, tmp_path):
exif = reloaded._getexif()
assert exif[274] == 1

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_exif_from_jpg(self, tmp_path):
with Image.open("Tests/images/pil_sample_rgb.jpg") as im:
test_file = str(tmp_path / "temp.png")
Expand Down
5 changes: 5 additions & 0 deletions Tests/test_file_webp_metadata.py
@@ -1,5 +1,7 @@
from io import BytesIO

import pytest

from PIL import Image

from .helper import skip_unless_feature
Expand Down Expand Up @@ -39,6 +41,7 @@ def test_read_exif_metadata_without_prefix():
assert exif[305] == "Adobe Photoshop CS6 (Macintosh)"


@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_write_exif_metadata():
file_path = "Tests/images/flower.jpg"
test_buffer = BytesIO()
Expand Down Expand Up @@ -71,6 +74,7 @@ def test_read_icc_profile():
assert icc == expected_icc


@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_write_icc_metadata():
file_path = "Tests/images/flower2.jpg"
test_buffer = BytesIO()
Expand All @@ -88,6 +92,7 @@ def test_write_icc_metadata():
assert webp_icc_profile == expected_icc_profile, "Webp ICC didn't match"


@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_read_no_exif():
file_path = "Tests/images/flower.jpg"
test_buffer = BytesIO()
Expand Down
1 change: 1 addition & 0 deletions Tests/test_image.py
Expand Up @@ -652,6 +652,7 @@ def act(fp):

assert not fp.closed

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_exif_jpeg(self, tmp_path):
with Image.open("Tests/images/exif-72dpi-int.jpg") as im: # Little endian
exif = im.getexif()
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_image_resample.py
Expand Up @@ -455,6 +455,7 @@ def split_range(size, tiles):
tiled.paste(tile, (x0, y0))
return tiled

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_tiles(self):
with Image.open("Tests/images/flower.jpg") as im:
assert im.size == (480, 360)
Expand All @@ -465,6 +466,7 @@ def test_tiles(self):
tiled = self.resize_tiled(im, dst_size, *tiles)
assert_image_similar(reference, tiled, 0.01)

@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_subsample(self):
# This test shows advantages of the subpixel resizing
# after supersampling (e.g. during JPEG decoding).
Expand Down
1 change: 1 addition & 0 deletions Tests/test_image_thumbnail.py
Expand Up @@ -88,6 +88,7 @@ def test_no_resize():
assert im.size == (64, 64)


@pytest.mark.valgrind_known_error(reason="Known Failing")
def test_DCT_scaling_edges():
# Make an image with red borders and size (N * 8) + 1 to cross DCT grid
im = Image.new("RGB", (257, 257), "red")
Expand Down