From 35b7327b3cced0cf968ee8bca554dda0de361b7c Mon Sep 17 00:00:00 2001 From: Noah Pendleton <2538614+noahp@users.noreply.github.com> Date: Mon, 12 Sep 2022 11:04:31 -0400 Subject: [PATCH] Fail when new snapshots are added and not updated See upstream: https://github.com/syrusakbary/snapshottest/issues/73 If not configured to update the tests, fail when new tests are added. --- README.md | 8 +++++--- setup.py | 2 +- snapshottest/module.py | 5 ++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b190395..d0ba532 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +> **NOTE:** this is a fork to fix https://github.com/syrusakbary/snapshottest/issues/73 + # SnapshotTest [![travis][travis-image]][travis-url] [![pypi][pypi-image]][pypi-url] [travis-image]: https://img.shields.io/travis/syrusakbary/snapshottest.svg?style=flat @@ -74,7 +76,7 @@ Check the [Django example](https://github.com/syrusakbary/snapshottest/tree/mast ## Disabling terminal colors -Set the environment variable `ANSI_COLORS_DISABLED` (to any value), e.g. +Set the environment variable `ANSI_COLORS_DISABLED` (to any value), e.g. ANSI_COLORS_DISABLED=1 pytest @@ -88,7 +90,7 @@ make develop ``` After developing, ensure your code is formatted properly by running: - + ```sh make format-fix ``` @@ -101,7 +103,7 @@ make lint make test ``` -To test locally on all supported Python versions, you can use +To test locally on all supported Python versions, you can use [tox](https://tox.readthedocs.io/): ```sh diff --git a/setup.py b/setup.py index 70089b7..3b84f3f 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name="snapshottest", - version="1.0.0a0", + version="1.0.0a0+memfault0", description="Snapshot testing for pytest, unittest, Django, and Nose", long_description=readme, long_description_content_type="text/markdown", diff --git a/snapshottest/module.py b/snapshottest/module.py index e31b46c..ed8394a 100644 --- a/snapshottest/module.py +++ b/snapshottest/module.py @@ -255,7 +255,10 @@ def assert_match(self, value, name=""): try: prev_snapshot = self.module[self.test_name] except SnapshotNotFound: - self.store(value) # first time this test has been seen + if self.update: + self.store(value) # first time this test has been seen + else: + raise else: try: self.assert_value_matches_snapshot(value, prev_snapshot)