Add compat for old pytest in type hints

This commit is contained in:
Denis Laxalde 2023-10-06 11:45:48 +02:00 committed by Denis Laxalde
parent fabf3c142b
commit 4035f1a3da
3 changed files with 22 additions and 3 deletions

View file

@ -10,6 +10,7 @@
* Improve test coverage by running an HTTP server to fake the Patroni API (#55
by @dlax).
* Work around old pytest versions in type annotations in the test suite.
* Declare compatibility with click version 7.1 (or higher).
## check_patroni 1.0.0 - 2023-08-28

View file

@ -45,7 +45,8 @@ setup(
],
extras_require={
"test": [
"pytest",
"importlib_metadata; python_version < '3.8'",
"pytest >= 6.0.2",
],
},
entry_points={

View file

@ -1,6 +1,12 @@
import sys
from pathlib import Path
from threading import Thread
from typing import Any, Iterator
from typing import Any, Iterator, Tuple
if sys.version_info >= (3, 8):
from importlib.metadata import version as metadata_version
else:
from importlib_metadata import version as metadata_version
import pytest
from click.testing import CliRunner
@ -8,6 +14,17 @@ from click.testing import CliRunner
from . import PatroniAPI
def numversion(pkgname: str) -> Tuple[int, ...]:
version = metadata_version(pkgname)
return tuple(int(v) for v in version.split(".", 3))
if numversion("pytest") >= (6, 2):
TempPathFactory = pytest.TempPathFactory
else:
from _pytest.tmpdir import TempPathFactory
@pytest.fixture(
params=[False, True],
ids=lambda v: "new-replica-state" if v else "old-replica-state",
@ -23,7 +40,7 @@ def datadir() -> Path:
@pytest.fixture(scope="session")
def patroni_api(
tmp_path_factory: pytest.TempPathFactory, datadir: Path
tmp_path_factory: TempPathFactory, datadir: Path
) -> Iterator[PatroniAPI]:
"""A fake HTTP server for the Patroni API serving files from a temporary
directory.