Work around nagiosplugin issue about stdout in tests
We basically apply the change from https://github.com/mpounsett/nagiosplugin/issues/24 as a fixture, but only when nagiosplugin's version is old.
This commit is contained in:
parent
4035f1a3da
commit
a8c4a3125d
|
@ -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
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue