Skip to content

Commit cd6a212

Browse files
committed
Run slow tests on valgrind, but without timeout
1 parent 7e4d8e2 commit cd6a212

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

Tests/helper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,12 @@ def assert_tuple_approx_equal(
161161
pytest.fail(msg + ": " + repr(actuals) + " != " + repr(targets))
162162

163163

164+
def timeout_unless_slower_valgrind(timeout: float) -> pytest.MarkDecorator:
165+
if "PILLOW_VALGRIND_TEST" in os.environ:
166+
return pytest.mark.pil_noop_mark()
167+
return pytest.mark.timeout(timeout)
168+
169+
164170
def skip_unless_feature(feature: str) -> pytest.MarkDecorator:
165171
reason = f"{feature} not available"
166172
return pytest.mark.skipif(not features.check(feature), reason=reason)

Tests/test_file_pdf.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
from PIL import Image, PdfParser, features
1515

16-
from .helper import hopper, mark_if_feature_version, skip_unless_feature
16+
from .helper import (
17+
hopper,
18+
mark_if_feature_version,
19+
skip_unless_feature,
20+
timeout_unless_slower_valgrind,
21+
)
1722

1823

1924
def helper_save_as_pdf(tmp_path: Path, mode: str, **kwargs: Any) -> str:
@@ -339,8 +344,7 @@ def test_pdf_append_to_bytesio() -> None:
339344
assert len(f.getvalue()) > initial_size
340345

341346

342-
@pytest.mark.timeout(1)
343-
@pytest.mark.skipif("PILLOW_VALGRIND_TEST" in os.environ, reason="Valgrind is slower")
347+
@timeout_unless_slower_valgrind(1)
344348
@pytest.mark.parametrize("newline", (b"\r", b"\n"))
345349
def test_redos(newline: bytes) -> None:
346350
malicious = b" trailer<<>>" + newline * 3456

Tests/test_image.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
is_win32,
3535
mark_if_feature_version,
3636
skip_unless_feature,
37+
timeout_unless_slower_valgrind,
3738
)
3839

3940
ElementTree: ModuleType | None
@@ -572,10 +573,7 @@ def test_check_size(self) -> None:
572573
i = Image.new("RGB", [1, 1])
573574
assert isinstance(i.size, tuple)
574575

575-
@pytest.mark.timeout(0.75)
576-
@pytest.mark.skipif(
577-
"PILLOW_VALGRIND_TEST" in os.environ, reason="Valgrind is slower"
578-
)
576+
@timeout_unless_slower_valgrind(0.75)
579577
@pytest.mark.parametrize("size", ((0, 100000000), (100000000, 0)))
580578
def test_empty_image(self, size: tuple[int, int]) -> None:
581579
Image.new("RGB", size)

0 commit comments

Comments
 (0)