Golden master testing for pytest with automatic regeneration.
Project description
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
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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99938a0aec0d0a5eda429cd626834114d05dbcb9dd4a1138c52d734258a63325
|
|
| MD5 |
4b8d6ad3e4433d41068d4d46caaa8203
|
|
| BLAKE2b-256 |
69983c6985de3721258eddad7e99c9299e8cbbe2d56f56fc080045b9610334c7
|
Provenance
The following attestation bundles were made for pytest_remaster-0.0.1a0.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.1a0.tar.gz -
Subject digest:
99938a0aec0d0a5eda429cd626834114d05dbcb9dd4a1138c52d734258a63325 - Sigstore transparency entry: 1154479574
- Sigstore integration time:
-
Permalink:
Pierre-Sassoulas/pytest-remaster@fa31178f66de0fd70a9bbde7b4950e0bb96d3129 -
Branch / Tag:
refs/tags/v0.0.1a0 - Owner: https://github.com/Pierre-Sassoulas
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@fa31178f66de0fd70a9bbde7b4950e0bb96d3129 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytest_remaster-0.0.1a0-py3-none-any.whl.
File metadata
- Download URL: pytest_remaster-0.0.1a0-py3-none-any.whl
- Upload date:
- Size: 7.2 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 |
53933358859bb52a1d243ae49714595c26bf4cd9ee733dda50ead08d9e254d7c
|
|
| MD5 |
c1f989d0d9657b726b74cf287f6ec7a2
|
|
| BLAKE2b-256 |
36db4b2bdfef7f4036a9364309266422fbeb36235862727305df421d3b0f82dc
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_remaster-0.0.1a0-py3-none-any.whl -
Subject digest:
53933358859bb52a1d243ae49714595c26bf4cd9ee733dda50ead08d9e254d7c - Sigstore transparency entry: 1154479581
- Sigstore integration time:
-
Permalink:
Pierre-Sassoulas/pytest-remaster@fa31178f66de0fd70a9bbde7b4950e0bb96d3129 -
Branch / Tag:
refs/tags/v0.0.1a0 - Owner: https://github.com/Pierre-Sassoulas
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@fa31178f66de0fd70a9bbde7b4950e0bb96d3129 -
Trigger Event:
release
-
Statement type: