diff --git a/src/syrupy/__init__.py b/src/syrupy/__init__.py index 560ddb0f..1793b67a 100644 --- a/src/syrupy/__init__.py +++ b/src/syrupy/__init__.py @@ -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 diff --git a/tests/integration/test_pytest_extension.py b/tests/integration/test_pytest_extension.py index 1fd1a9a0..2c34efe9 100644 --- a/tests/integration/test_pytest_extension.py +++ b/tests/integration/test_pytest_extension.py @@ -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