Skip to main content

Pytest plugin for golden master (characterisation) testing with automatic expected file regeneration.

Project description

PyPI version PyPI - Python Version PyPI - License

pytest-remaster

Pytest plugin for golden master (characterisation) testing with automatic expected file regeneration.

Example 1: directory per test case

Each test case is a directory with input files and numbered expected outputs:

tests/cases/
  greet/hello/
    command             # input
    expected_0.txt      # first expected output
  help/unknown/
    command
    expected_0.txt
    expected_1.txt      # multiple outputs supported
import pytest
from pytest_remaster import CaseData, GoldenMaster, discover_test_cases

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

@pytest.mark.parametrize("case", discover_test_cases(CASES_DIR))
def test_command(case: CaseData, golden_master: GoldenMaster) -> None:
    cmd = (case.input / "command").read_text().strip()
    golden_master.check_all(lambda: my_app(cmd), case.input, suffix=".txt")

Example 2: one file per test case

Each test case is a source file, with expected output derived from the filename:

tests/functional/
  arguments.py          # input (source to lint)
  arguments.txt         # expected output
  anomalous.py
  anomalous.txt
import pytest
from pytest_remaster import CaseData, GoldenMaster, discover_test_files

FUNC_DIR = Path(__file__).parent / "functional"

@pytest.mark.parametrize("case", discover_test_files(FUNC_DIR, "*.py"))
def test_lint(case: CaseData, golden_master: GoldenMaster) -> None:
    golden_master.check(lambda: lint(case.input), case.expected(suffix=".txt"))

Both examples auto-update expected files on mismatch. Review the diff in git, rerun. Pass --no-remaster for strict comparison.

API

golden_master.check(actual, expected_path)

Compare one value against one expected file:

golden_master.check(output, case.expected(suffix=".txt"))
golden_master.check(data, path / "db.json", normalizer=json_normalizer)

Options: serializer=str, normalizer=None.

golden_master.check_all(actuals, directory)

Compare a list against expected_0, expected_1, ... files in a directory:

golden_master.check_all(lambda: my_app(cmd), case.input, suffix=".txt")

Options: serializer=str, normalizer=None, suffix="".

Discovery

discover_test_cases(base_dir)               # leaf directories → CaseData
discover_test_files(base_dir, "*.py")       # files by pattern → CaseData

CaseData.input is the source path. CaseData.expected(index, suffix) derives expected file paths.

FilePatchRegistry

Auto-load fixture files from case directories and patch mock targets:

from pytest_remaster import FilePatchRegistry

patcher = FilePatchRegistry()
patcher.register("command", loader=str.strip)
patcher.register("salt.json", target="pepper.Pepper", attr="return_value.low.side_effect")
patcher.register("tiger.json", target="requests.get", attr="return_value.json.side_effect", default=[])
patcher.register("user.json", default={"name": "default"})

@pytest.mark.parametrize("case", discover_test_cases(CASES_DIR))
def test_command(case, golden_master):
    with patcher.mock(case) as loaded:
        events = run_command(loaded["command"], loaded["user.json"])
        golden_master.check_all(events, case.input)

Options: target=None (load only), attr="return_value" (nested mock attribute path), loader=json.loads, default=None.

Configuration

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

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.1b0.tar.gz (18.9 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.1b0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_remaster-0.0.1b0.tar.gz
  • Upload date:
  • Size: 18.9 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.1b0.tar.gz
Algorithm Hash digest
SHA256 d9280296e186964ef990909acaebee3c7735bb687639488b5d2429e1e5a2a012
MD5 d2bede6ae08d0e9285022b010f364d70
BLAKE2b-256 b3ade222a780a607d2a7693f38cee344926da5002bdff7948656bd9abb1a5748

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_remaster-0.0.1b0.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.1b0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_remaster-0.0.1b0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2b4b67f9f9bd9fa707d55ac76d2a8de446ed035b89f55a83610932195d12957
MD5 1e4a233ed5803d141c57e07594d65989
BLAKE2b-256 9c843086d9445cb9a7e3301923d02b278fd9159d1df740c340353ef6e53e5e45

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_remaster-0.0.1b0-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