Pytest plugin for golden master (characterisation) testing with automatic expected file regeneration.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_remaster-0.0.1a3.tar.gz.
File metadata
- Download URL: pytest_remaster-0.0.1a3.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c68551a61c3be034640eff1c6cb22937845f88b98c600029b6f5506e62e7580e
|
|
| MD5 |
4064067291ae7380ef31c5317f3e150f
|
|
| BLAKE2b-256 |
f612057b02eb71f513b812a894b9b8df2d79a0b152bdaffed3f0c9f082bef52f
|
Provenance
The following attestation bundles were made for pytest_remaster-0.0.1a3.tar.gz:
Publisher:
release.yaml on Pierre-Sassoulas/pytest-remaster
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_remaster-0.0.1a3.tar.gz -
Subject digest:
c68551a61c3be034640eff1c6cb22937845f88b98c600029b6f5506e62e7580e - Sigstore transparency entry: 1155082960
- Sigstore integration time:
-
Permalink:
Pierre-Sassoulas/pytest-remaster@20c9805a936991556313b2728bb4ae8f23a840b1 -
Branch / Tag:
refs/tags/v0.0.1a3 - Owner: https://github.com/Pierre-Sassoulas
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@20c9805a936991556313b2728bb4ae8f23a840b1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_remaster-0.0.1a3-py3-none-any.whl.
File metadata
- Download URL: pytest_remaster-0.0.1a3-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b05d80beca46477785387fac3f38bb85308e4edbc658223537ff9e3af036f970
|
|
| MD5 |
1f6e90731541ee3f40cf36d6919d8d66
|
|
| BLAKE2b-256 |
8befd442c7f6a86750d98c0d5d7425d96d9ed7b0b4141196e61f649b1eb136af
|
Provenance
The following attestation bundles were made for pytest_remaster-0.0.1a3-py3-none-any.whl:
Publisher:
release.yaml on Pierre-Sassoulas/pytest-remaster
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_remaster-0.0.1a3-py3-none-any.whl -
Subject digest:
b05d80beca46477785387fac3f38bb85308e4edbc658223537ff9e3af036f970 - Sigstore transparency entry: 1155082962
- Sigstore integration time:
-
Permalink:
Pierre-Sassoulas/pytest-remaster@20c9805a936991556313b2728bb4ae8f23a840b1 -
Branch / Tag:
refs/tags/v0.0.1a3 - Owner: https://github.com/Pierre-Sassoulas
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@20c9805a936991556313b2728bb4ae8f23a840b1 -
Trigger Event:
release
-
Statement type: