diff --git a/tests/conftest.py b/tests/conftest.py index 5c03cd04..05088071 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,6 +3,7 @@ from __future__ import annotations +import logging import platform import sys from pathlib import Path @@ -17,6 +18,27 @@ from ocrmypdf.cli import get_options_and_plugins from ocrmypdf.exceptions import ExitCode +class Gs106WarningFilter(logging.Filter): + """Filter out expected Ghostscript 10.6.x warning from test logs.""" + + def filter(self, record: logging.LogRecord) -> bool: + # Allow all records except the expected Ghostscript 10.6.x warning + if "Ghostscript 10.6.x contains JPEG encoding errors" in record.getMessage(): + return False + return True + + +@pytest.fixture(autouse=True) +def suppress_gs106_warning(): + """Suppress the expected Ghostscript 10.6.x JPEG encoding warning in tests.""" + # Add filter to root logger to suppress expected warnings + root_logger = logging.getLogger() + warning_filter = Gs106WarningFilter() + root_logger.addFilter(warning_filter) + yield + root_logger.removeFilter(warning_filter) + + def is_linux(): return platform.system() == 'Linux' diff --git a/tests/test_ghostscript.py b/tests/test_ghostscript.py index 79250d3b..7103f162 100644 --- a/tests/test_ghostscript.py +++ b/tests/test_ghostscript.py @@ -84,6 +84,8 @@ def test_gs_render_failure(resources, outpdf, caplog): exitcode = run_ocrmypdf_api( resources / 'blank.pdf', outpdf, + '--output-type', + 'pdfa', # Required to trigger Ghostscript PDF/A generation '--plugin', 'tests/plugins/tesseract_noop.py', '--plugin', @@ -110,6 +112,8 @@ def test_ghostscript_pdfa_failure(resources, outpdf, caplog): exitcode = run_ocrmypdf_api( resources / 'francais.pdf', outpdf, + '--output-type', + 'pdfa', # Required to trigger Ghostscript PDF/A generation '--plugin', 'tests/plugins/tesseract_noop.py', '--plugin', @@ -136,6 +140,8 @@ def test_ghostscript_mandatory_color_conversion(resources, outpdf): check_ocrmypdf( resources / 'jbig2_baddevicen.pdf', outpdf, + '--output-type', + 'pdfa', # Required to trigger Ghostscript PDF/A generation '--plugin', 'tests/plugins/tesseract_noop.py', )