Skip to content
Snippets Groups Projects
Commit 71edbc19 authored by Yaroslav Dynnikov's avatar Yaroslav Dynnikov
Browse files

doc: supplement pytest fixtures with docstrings

It also provides better experience with various IDEs.
parent 16722f1d
No related branches found
No related tags found
1 merge request!274doc: supplement pytest fixtures with docstrings
Pipeline #12570 passed
...@@ -41,12 +41,15 @@ def pytest_addoption(parser): ...@@ -41,12 +41,15 @@ def pytest_addoption(parser):
"--delay", "--delay",
action="store", action="store",
default=None, default=None,
help="Delay between steps for fandomized tests", help="Delay between steps for randomized tests",
) )
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def seed(pytestconfig): def seed(pytestconfig):
"""Return a seed for randomized tests. Unless passed via
command-line options it is generated automatically.
"""
seed = pytestconfig.getoption("seed") seed = pytestconfig.getoption("seed")
return seed if seed else generate_seed() return seed if seed else generate_seed()
...@@ -584,11 +587,14 @@ class Cluster: ...@@ -584,11 +587,14 @@ class Cluster:
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def compile() -> None: def compile() -> None:
"""Run `cargo build` before tests."""
assert subprocess.call(["cargo", "build"]) == 0, "cargo build failed" assert subprocess.call(["cargo", "build"]) == 0, "cargo build failed"
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def binary_path(compile, pytestconfig) -> str: def binary_path(compile) -> str:
"""Path to the picodata binary, e.g. "./target/debug/picodata"."""
metadata = subprocess.check_output(["cargo", "metadata", "--format-version=1"]) metadata = subprocess.check_output(["cargo", "metadata", "--format-version=1"])
target = json.loads(metadata)["target_directory"] target = json.loads(metadata)["target_directory"]
return os.path.realpath(os.path.join(target, "debug/picodata")) return os.path.realpath(os.path.join(target, "debug/picodata"))
...@@ -596,6 +602,7 @@ def binary_path(compile, pytestconfig) -> str: ...@@ -596,6 +602,7 @@ def binary_path(compile, pytestconfig) -> str:
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def cluster_ids(xdist_worker_number) -> Iterator[str]: def cluster_ids(xdist_worker_number) -> Iterator[str]:
"""Unique `clister_id` generator."""
return (f"cluster-{xdist_worker_number}-{i}" for i in count()) return (f"cluster-{xdist_worker_number}-{i}" for i in count())
...@@ -606,6 +613,7 @@ def cluster( ...@@ -606,6 +613,7 @@ def cluster(
xdist_worker_number, xdist_worker_number,
cluster_ids, cluster_ids,
) -> Generator[Cluster, None, None]: ) -> Generator[Cluster, None, None]:
"""Return a `Cluster` object capable of deploying test clusters."""
n = xdist_worker_number n = xdist_worker_number
assert isinstance(n, int) assert isinstance(n, int)
assert n >= 0 assert n >= 0
...@@ -629,6 +637,7 @@ def cluster( ...@@ -629,6 +637,7 @@ def cluster(
@pytest.fixture @pytest.fixture
def instance(cluster: Cluster) -> Generator[Instance, None, None]: def instance(cluster: Cluster) -> Generator[Instance, None, None]:
"""Returns a deployed instance forming a single-node cluster."""
cluster.deploy(instance_count=1) cluster.deploy(instance_count=1)
yield cluster[0] yield cluster[0]
...@@ -647,7 +656,7 @@ def retrying(fn, timeout=3): ...@@ -647,7 +656,7 @@ def retrying(fn, timeout=3):
def pid_alive(pid): def pid_alive(pid):
"""Check For the existence of a unix pid.""" """Check for the existence of a unix pid."""
try: try:
os.kill(pid, 0) os.kill(pid, 0)
except OSError: except OSError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment