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

feat: fail unused snapshots #77

Merged
merged 14 commits into from
Dec 29, 2019
Prev Previous commit
Next Next commit
cr: more explicit option
iamogbz committed Dec 29, 2019
commit 01e942872cab215b25d78c5200b7e40ed7d0b6dd
6 changes: 3 additions & 3 deletions src/syrupy/__init__.py
Original file line number Diff line number Diff line change
@@ -26,10 +26,10 @@ def pytest_addoption(parser: Any) -> None:
help="Update snapshots",
)
group.addoption(
"--unused-warn",
"--snapshot-unused-warn",
action="store_true",
default=False,
dest="warn_unused",
dest="warn_unused_snapshots",
help="Do not fail on unused snapshots",
)

@@ -55,7 +55,7 @@ def pytest_sessionstart(session: Any) -> None:
"""
config = session.config
session._syrupy = SnapshotSession(
warn_unused=config.option.warn_unused,
warn_unused_snapshots=config.option.warn_unused_snapshots,
update_snapshots=config.option.update_snapshots,
base_dir=config.rootdir,
)
10 changes: 6 additions & 4 deletions src/syrupy/session.py
Original file line number Diff line number Diff line change
@@ -42,8 +42,10 @@ def empty_snapshot_groups() -> "SnapshotGroups":


class SnapshotSession:
def __init__(self, *, warn_unused: bool, update_snapshots: bool, base_dir: str):
self.warn_unused = warn_unused
def __init__(
self, *, warn_unused_snapshots: bool, update_snapshots: bool, base_dir: str
):
self.warn_unused_snapshots = warn_unused_snapshots
self.update_snapshots = update_snapshots
self.base_dir = base_dir
self.report: List[str] = []
@@ -104,7 +106,7 @@ def finish(self) -> int:
else:
text_singular = "{} snapshot unused."
text_plural = "{} snapshots unused."
if self.update_snapshots or self.warn_unused:
if self.update_snapshots or self.warn_unused_snapshots:
text_count = warning_style(n_unused)
else:
text_count = error_style(n_unused)
@@ -132,7 +134,7 @@ def finish(self) -> int:
" to delete the unused snapshots."
)
)
if not self.warn_unused:
if not self.warn_unused_snapshots:
exitstatus = 1
return exitstatus

2 changes: 1 addition & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -233,7 +233,7 @@ def test_unused_snapshots(stubs):
def test_unused_snapshots_warning(stubs):
_, testdir, tests, _ = stubs
testdir.makepyfile(test_file="\n\n".join(tests[k] for k in tests if k != "unused"))
result = testdir.runpytest("-v", "--unused-warn")
result = testdir.runpytest("-v", "--snapshot-unused-warn")
result_stdout = clean_output(result.stdout.str())
assert "snapshots generated" not in result_stdout
assert "4 snapshots passed" in result_stdout