Add compat for old pytest in type hints
This commit is contained in:
parent
fabf3c142b
commit
4035f1a3da
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
* Improve test coverage by running an HTTP server to fake the Patroni API (#55
|
* Improve test coverage by running an HTTP server to fake the Patroni API (#55
|
||||||
by @dlax).
|
by @dlax).
|
||||||
|
* Work around old pytest versions in type annotations in the test suite.
|
||||||
* Declare compatibility with click version 7.1 (or higher).
|
* Declare compatibility with click version 7.1 (or higher).
|
||||||
|
|
||||||
## check_patroni 1.0.0 - 2023-08-28
|
## check_patroni 1.0.0 - 2023-08-28
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -45,7 +45,8 @@ setup(
|
||||||
],
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
"test": [
|
"test": [
|
||||||
"pytest",
|
"importlib_metadata; python_version < '3.8'",
|
||||||
|
"pytest >= 6.0.2",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
entry_points={
|
entry_points={
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from threading import Thread
|
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
|
import pytest
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
@ -8,6 +14,17 @@ from click.testing import CliRunner
|
||||||
from . import PatroniAPI
|
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(
|
@pytest.fixture(
|
||||||
params=[False, True],
|
params=[False, True],
|
||||||
ids=lambda v: "new-replica-state" if v else "old-replica-state",
|
ids=lambda v: "new-replica-state" if v else "old-replica-state",
|
||||||
|
@ -23,7 +40,7 @@ def datadir() -> Path:
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def patroni_api(
|
def patroni_api(
|
||||||
tmp_path_factory: pytest.TempPathFactory, datadir: Path
|
tmp_path_factory: TempPathFactory, datadir: Path
|
||||||
) -> Iterator[PatroniAPI]:
|
) -> Iterator[PatroniAPI]:
|
||||||
"""A fake HTTP server for the Patroni API serving files from a temporary
|
"""A fake HTTP server for the Patroni API serving files from a temporary
|
||||||
directory.
|
directory.
|
||||||
|
|
Loading…
Reference in a new issue