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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_remaster-0.0.1a5.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.1a5.tar.gz
Algorithm Hash digest
SHA256 82f810a7a5eddd55810a947a09254f5662a21f79d14489f5104ad80c8a6ca175
MD5 46605b67ea4e1a3585e5bdbc334deb9a
BLAKE2b-256 0b61fc5a2362fe12b46a51193565de41b0213e4029d8e27d8b18107a183f2b5d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pytest_remaster-0.0.1a5-py3-none-any.whl
Algorithm Hash digest
SHA256 549b82ef30f8176f6804f8d30105d8d488623bc2f14490ccd99ca40d815a607a
MD5 236d6e765d9a1cbd2baa304f908aee7a
BLAKE2b-256 cddc1d3b064460a63046fbd90b3ad4c78f7ad62a8577fc308d60a99c8a3d1131

See more details on using hashes here.

Provenance

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