Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show snapshot data in report when does not exist #191

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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