Skip to main content

Golden master testing for pytest with automatic regeneration.

Project description

PyPI version PyPI - Python Version PyPI - License

pytest-remaster

Framework for golden master testing for pytest with automatic regeneration of the golden master.

Installation

pip install pytest-remaster

Quick start

Create test case directories with input files and expected output files:

tests/cases/
  greet/hello/
    command          # input: "hello Alice"
    result_0         # expected: "[#general] :wave: Hello, Alice!"
  greet/goodbye/
    command          # input: "goodbye Bob"
    result_0         # expected: "[#general] :wave: Goodbye, Bob!"
    result_1         # expected: "[#general] :door: Bob has left the chat."

Write a parametrized test:

from pathlib import Path

import pytest

from pytest_remaster import GoldenMaster, discover_test_cases

CASES_DIR = Path(__file__).parent / "cases"


@pytest.mark.parametrize("case", discover_test_cases(CASES_DIR))
def test_command(case: Path, golden_master: GoldenMaster) -> None:
    cmd = (case / "command").read_text().strip()
    golden_master.check_all(lambda: run_command(cmd), directory=case)

discover_test_cases finds leaf directories and generates nice test IDs automatically (e.g. test_command[greet/hello]).

API

golden_master fixture

check(actual, expected_path, serializer=str) — Compare one actual value (or callable) against one expected file:

golden_master.check(output, case / "expected.txt")
golden_master.check(data, case / "db.json", serializer=json.dumps)
golden_master.check(lambda: run(), case / "output.txt")

check_all(*actuals, directory, serializer=str) — Compare multiple values against result_0, result_1, ... files in a directory:

golden_master.check_all(*events, directory=case)
golden_master.check_all(lambda: run_command(cmd), directory=case)

Discovery functions

discover_test_cases(base_dir) — Find leaf directories (directories containing only files). Returns pytest.param objects with relative path IDs.

discover_test_files(base_dir, pattern) — Find files matching a glob pattern. Returns pytest.param objects with relative path IDs.

Behavior

  • --remaster (default): When output doesn't match, the expected file is updated and the test fails with "please review and relaunch". Review the diff in git, then rerun.
  • --no-remaster: When output doesn't match, the test fails with a unified diff. No files are modified.

The default can be changed in pyproject.toml:

[tool.pytest.ini_options]
remaster-by-default = false

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_remaster-0.0.1a0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_remaster-0.0.1a0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest_remaster-0.0.1a0.tar.gz.

File metadata

  • Download URL: pytest_remaster-0.0.1a0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_remaster-0.0.1a0.tar.gz
Algorithm Hash digest
SHA256 99938a0aec0d0a5eda429cd626834114d05dbcb9dd4a1138c52d734258a63325
MD5 4b8d6ad3e4433d41068d4d46caaa8203
BLAKE2b-256 69983c6985de3721258eddad7e99c9299e8cbbe2d56f56fc080045b9610334c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_remaster-0.0.1a0.tar.gz:

Publisher: release.yaml on Pierre-Sassoulas/pytest-remaster

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_remaster-0.0.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_remaster-0.0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 53933358859bb52a1d243ae49714595c26bf4cd9ee733dda50ead08d9e254d7c
MD5 c1f989d0d9657b726b74cf287f6ec7a2
BLAKE2b-256 36db4b2bdfef7f4036a9364309266422fbeb36235862727305df421d3b0f82dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_remaster-0.0.1a0-py3-none-any.whl:

Publisher: release.yaml on Pierre-Sassoulas/pytest-remaster

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page