Skip to content

Commit

Permalink
Added option to only check snapshots and not update them
Browse files Browse the repository at this point in the history
  • Loading branch information
AKuederle committed Apr 17, 2024
1 parent 8d9ede2 commit 30c6ce1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tpcp/testing/_regression_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def pytest_addoption(parser):
dest="snapshot_update",
help="Update the snapshots.",
)
group.addoption(
"--snapshot-only-check",
action="store_true",
default=False,
dest="snapshot_only_check",
help="Update the snapshots.",
)
This will register the snapshot fixture that you can use in your tests.
Further, it will register the `--snapshot-update` commandline flag, which you can use to update the snapshots.
Expand Down Expand Up @@ -73,6 +81,10 @@ def __init__(self, request=None) -> None:
def _update(self):
return self.request.config.option.snapshot_update

@property
def _only_check(self):
return self.request.config.option.snapshot_only_check

@property
def _module(self):
return Path(self.request.node.fspath.strpath).parent
Expand Down Expand Up @@ -172,7 +184,13 @@ def assert_match(self, value: Union[str, pd.DataFrame, np.ndarray], name: Option
value_dtype = type(value)
try:
prev_snapshot = self._retrieve(value_dtype)
except SnapshotNotFoundError:
except SnapshotNotFoundError as e:
if self._only_check:
raise SnapshotNotFoundError(
"No corresponding snapshot file could be found. "
"Run pytest without the--snapshot-only-check flag to create a new "
"snapshot and store it in git"
) from e
self._store(value) # first time this test has been seen
except:
raise
Expand Down

0 comments on commit 30c6ce1

Please sign in to comment.