Skip to content

Commit

Permalink
fix: show snapshot data in report when does not exist (#191)
Browse files Browse the repository at this point in the history
* fix: show snapshot data in report when does not exist

* test: unsaved snapshot gets printed out
  • Loading branch information
iamogbz authored Apr 17, 2020
1 parent da8826a commit 7ebdca2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/syrupy/assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def executions(self) -> Dict[int, AssertionResult]:
return self._execution_results

def use_extension(
self, extension_class: Optional[Type["AbstractSyrupyExtension"]] = None,
self, extension_class: Optional[Type["AbstractSyrupyExtension"]] = None
) -> "SnapshotAssertion":
"""
Creates a new snapshot assertion fixture with the same options but using
Expand All @@ -92,12 +92,11 @@ def get_assert_diff(self, data: "SerializableData") -> List[str]:
assertion_result = self._execution_results[self.num_executions - 1]
snapshot_data = assertion_result.recalled_data
serialized_data = self.extension.serialize(data)
if snapshot_data is None:
return [gettext("Snapshot does not exist!")]

diff: List[str] = []
if snapshot_data is None:
diff.append(gettext("Snapshot does not exist!"))
if not assertion_result.success:
diff.extend(self.extension.diff_lines(serialized_data, snapshot_data))
diff.extend(self.extension.diff_lines(serialized_data, snapshot_data or ""))
return diff

def __call__(
Expand Down
6 changes: 4 additions & 2 deletions tests/test_integration_single_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ def test_passed_single(snapshot_single):
return {**testcases, **updated_testcases}


def test_unsaved_snapshots(testdir, testcases):
def test_unsaved_snapshots(snapshot, testdir, testcases):
testdir.makepyfile(test_file=testcases["passed"])
result = testdir.runpytest("-v")
assert "Snapshot does not exist" in clean_output(result.stdout.str())
output = clean_output(result.stdout.str())
assert "Snapshot does not exist" in output
assert "+ b'passed1'" in output
assert result.ret == 1


Expand Down

0 comments on commit 7ebdca2

Please sign in to comment.