Skip to content

Commit

Permalink
fix: hide empty snapshot report (#768)
Browse files Browse the repository at this point in the history
* fix: hide empty snapshot report

* test: does not print empty snapshot report
  • Loading branch information
iamogbz committed Jul 4, 2023
1 parent b322e69 commit 8f581d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/syrupy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,14 @@ def pytest_terminal_summary(
https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_terminal_summary
"""
with __terminal_color(config):
terminalreporter.write_sep("-", gettext("snapshot report summary"))
is_printing_report = False
for line in terminalreporter.config._syrupy.report.lines:
terminalreporter.write_line(line)
has_report_line = bool(line.strip())
if has_report_line and not is_printing_report:
terminalreporter.write_sep("-", gettext("snapshot report summary"))
is_printing_report = True
if is_printing_report:
terminalreporter.write_line(line)


@pytest.fixture
Expand Down
25 changes: 25 additions & 0 deletions tests/integration/test_pytest_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,28 @@ def test_example(snapshot):
"-v", "test_file.py", "--pyargs", "test_file", "--snapshot-update"
)
assert result.ret == 0


def test_does_not_print_empty_snapshot_report(testdir):
testdir.makeconftest("")
testcase_no_snapshots = """
def test_example(snapshot):
assert 1
"""
testcase_yes_snapshots = """
def test_example(snapshot):
assert snapshot == 1
"""
testdir.makepyfile(
test_file_no=testcase_no_snapshots, test_file_yes=testcase_yes_snapshots
)

result = testdir.runpytest("-v", "test_file_no.py", "--snapshot-update")
result.stdout.re_match_lines((r".*test_file_no.py.*"))
assert "snapshot report" not in result.stdout.str()
assert "test_file_yes" not in result.stdout.str()
assert result.ret == 0

result = testdir.runpytest("-v", "test_file_yes.py", "--snapshot-update")
result.stdout.re_match_lines((r".*test_file_yes.py.*", r".*snapshot report.*"))
assert result.ret == 0

0 comments on commit 8f581d5

Please sign in to comment.