Skip to content

Commit 8f581d5

Browse files
authored
fix: hide empty snapshot report (#768)
* fix: hide empty snapshot report * test: does not print empty snapshot report
1 parent b322e69 commit 8f581d5

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/syrupy/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,14 @@ def pytest_terminal_summary(
173173
https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_terminal_summary
174174
"""
175175
with __terminal_color(config):
176-
terminalreporter.write_sep("-", gettext("snapshot report summary"))
176+
is_printing_report = False
177177
for line in terminalreporter.config._syrupy.report.lines:
178-
terminalreporter.write_line(line)
178+
has_report_line = bool(line.strip())
179+
if has_report_line and not is_printing_report:
180+
terminalreporter.write_sep("-", gettext("snapshot report summary"))
181+
is_printing_report = True
182+
if is_printing_report:
183+
terminalreporter.write_line(line)
179184

180185

181186
@pytest.fixture

tests/integration/test_pytest_extension.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,28 @@ def test_example(snapshot):
3535
"-v", "test_file.py", "--pyargs", "test_file", "--snapshot-update"
3636
)
3737
assert result.ret == 0
38+
39+
40+
def test_does_not_print_empty_snapshot_report(testdir):
41+
testdir.makeconftest("")
42+
testcase_no_snapshots = """
43+
def test_example(snapshot):
44+
assert 1
45+
"""
46+
testcase_yes_snapshots = """
47+
def test_example(snapshot):
48+
assert snapshot == 1
49+
"""
50+
testdir.makepyfile(
51+
test_file_no=testcase_no_snapshots, test_file_yes=testcase_yes_snapshots
52+
)
53+
54+
result = testdir.runpytest("-v", "test_file_no.py", "--snapshot-update")
55+
result.stdout.re_match_lines((r".*test_file_no.py.*"))
56+
assert "snapshot report" not in result.stdout.str()
57+
assert "test_file_yes" not in result.stdout.str()
58+
assert result.ret == 0
59+
60+
result = testdir.runpytest("-v", "test_file_yes.py", "--snapshot-update")
61+
result.stdout.re_match_lines((r".*test_file_yes.py.*", r".*snapshot report.*"))
62+
assert result.ret == 0

0 commit comments

Comments
 (0)