Add an optional reference date for reproducible tests - #513
Open
ryanduguid wants to merge 2 commits into
Open
ryanduguid wants to merge 2 commits into
ryanduguid wants to merge 2 commits into
Conversation
Author
|
One design note, since the diff does not show the reasoning. The reference-date fixture is hand-rolled rather than built on freezegun or time-machine because python-stdnum has If you would rather take the dependency, this collapses to a few lines and I am happy to rewrite it that way. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tests involving birth dates and century selection can change behaviour as the calendar advances. This adds
STDNUM_TEST_DATE=YYYY-MM-DDfor downstream builds that need a reproducible reference date, while leaving development and scheduled tests on the real date.The pytest fixture validates the value before collection, temporarily replaces
datetime.date.today()and restores the original class after the session. Ordinary date construction andisinstancechecks remain compatible. Tox passes the variable through, and CONTRIBUTING explains how to choose a date appropriate for the release fixtures. No library validation code changes or runtime dependencies are added.Eight subprocess regression cases cover unset, explicit and invalid dates, date behaviour and restoration. The child suites do not inherit the parent's coverage file, avoiding incompatible coverage data with pytest-cov 5. The mypy environment installs pytest<9 so the new test imports remain compatible with its Python 3.9 target.
Fixes #431.
Verification:
6dbfc3f: CPython 3.8 through 3.14, PyPy 3.9, docs, flake8, mypy, headers and CodeQL. Run.STDNUM_TEST_DATE=2026-09-21: 421 passed, 9 skipped, 100% library coverage.Online tests were not run locally. The reference date must suit the release fixtures: a full run at 2024-01-01 fails a newer Romanian ONRC example, so the documentation uses 2026-09-21.