Skip to content

Commit

Permalink
fix: report usage of unknown inline-snapshot flags
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Oct 30, 2024
1 parent 9628d44 commit 48ef21a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/inline_snapshot/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def pytest_configure(config):
f"--inline-snapshot={','.join(flags)} can not be combined with xdist"
)

unknown_flags = flags - categories - {"disable", "review", "report", "short-report"}
if unknown_flags:
raise pytest.UsageError(
f"--inline-snapshot={','.join(sorted(unknown_flags))} is a unknown flag"
)

if "disable" in flags and flags != {"disable"}:
raise pytest.UsageError(
f"--inline-snapshot=disable can not be combined with other flags ({', '.join(flags-{'disable'})})"
Expand Down
4 changes: 4 additions & 0 deletions src/inline_snapshot/testing/_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def run_pytest(
env: dict[str, str] = {},
changed_files: Snapshot[dict[str, str]] | None = None,
report: Snapshot[str] | None = None,
stderr: Snapshot[str] | None = None,
returncode: Snapshot[int] | None = None,
) -> Example:
"""Run pytest with the given args and env variables in an seperate
Expand Down Expand Up @@ -255,6 +256,9 @@ def run_pytest(
if returncode is not None:
assert result.returncode == returncode

if stderr is not None:
assert result.stderr.decode() == stderr

if report is not None:

report_list = []
Expand Down
20 changes: 20 additions & 0 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,23 @@ def test_a():
"""
),
)


def test_unknown_flag():

Example(
"""\
def test_a():
assert 1==1
"""
).run_pytest(
["--inline-snapshot=creaigflen"],
report=snapshot(""),
returncode=snapshot(4),
stderr=snapshot(
"""\
ERROR: --inline-snapshot=creaigflen is a unknown flag
"""
),
)

0 comments on commit 48ef21a

Please sign in to comment.