diff --git a/CHANGELOG.md b/CHANGELOG.md index 02bc25b..ebcb4c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ by @dlax). * Work around old pytest versions in type annotations in the test suite. * Declare compatibility with click version 7.1 (or higher). +* In tests, work around nagiosplugin 1.3.2 not properly handling stdout + redirection. ## check_patroni 1.0.0 - 2023-08-28 diff --git a/tests/conftest.py b/tests/conftest.py index 3da8d61..3a071c0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,9 @@ +import logging import sys from pathlib import Path from threading import Thread from typing import Any, Iterator, Tuple +from unittest.mock import patch if sys.version_info >= (3, 8): from importlib.metadata import version as metadata_version @@ -13,6 +15,8 @@ from click.testing import CliRunner from . import PatroniAPI +logger = logging.getLogger(__name__) + def numversion(pkgname: str) -> Tuple[int, ...]: version = metadata_version(pkgname) @@ -25,6 +29,19 @@ else: from _pytest.tmpdir import TempPathFactory +@pytest.fixture(scope="session", autouse=True) +def nagioplugin_runtime_stdout() -> Iterator[None]: + # work around https://github.com/mpounsett/nagiosplugin/issues/24 when + # nagiosplugin is older than 1.3.3 + if numversion("nagiosplugin") < (1, 3, 3): + target = "nagiosplugin.runtime.Runtime.stdout" + with patch(target, None): + logger.warning("patching %r", target) + yield None + else: + yield None + + @pytest.fixture( params=[False, True], ids=lambda v: "new-replica-state" if v else "old-replica-state",