diff --git a/src/ocrmypdf/_sync.py b/src/ocrmypdf/_sync.py index 83de4150..af32ad8c 100644 --- a/src/ocrmypdf/_sync.py +++ b/src/ocrmypdf/_sync.py @@ -302,7 +302,7 @@ def exec_concurrent(context: PdfContext): copy_final(pdf, options.output_file, context) -def configure_debug_logging(log_filename, prefix: str = ''): +def configure_debug_logging(log_filename: Path, prefix: str = ''): """ Create a debug log file at a specified location. @@ -340,7 +340,9 @@ def run_pipeline(options, *, plugin_manager, api=False): # Debug log for command line interface only with verbose output # See https://github.com/pytest-dev/pytest/issues/5502 for why we skip this # when pytest is running - debug_log_handler = configure_debug_logging(Path(work_folder) / "debug.log") + debug_log_handler = configure_debug_logging( + Path(work_folder) / "debug.log" + ) # pragma: no cover pikepdf_enable_mmap() diff --git a/tests/test_logging.py b/tests/test_logging.py new file mode 100644 index 00000000..5fac42b4 --- /dev/null +++ b/tests/test_logging.py @@ -0,0 +1,21 @@ +# © 2021 James R. Barlow: github.com/jbarlow83 +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import logging + +import pytest + +from ocrmypdf._sync import configure_debug_logging + + +def test_debug_logging(tmp_path): + # Just exercise the debug logger but don't validate it + # See https://github.com/pytest-dev/pytest/issues/5502 for pytest logging quirks + prefix = 'test_debug_logging' + log = logging.getLogger(prefix) + handler = configure_debug_logging(tmp_path, prefix) + log.info("test message") + log.removeHandler(handler)