Skip to content

UsageError("unmanaged values can not be compared with snapshots") when using -k flag #355#356

Merged
15r10nk merged 1 commit intomainfrom
error-output
Mar 1, 2026
Merged

UsageError("unmanaged values can not be compared with snapshots") when using -k flag #355#356
15r10nk merged 1 commit intomainfrom
error-output

Conversation

@15r10nk
Copy link
Copy Markdown
Owner

@15r10nk 15r10nk commented Feb 26, 2026

Description

Related Issue(s)

Checklist

  • I have tested my changes thoroughly (you can download the test coverage with hatch run cov:github).
  • I have added/updated relevant documentation.
  • I have added tests for new functionality (if applicable).
  • I have reviewed my own code for errors.
  • I have added a changelog entry with hatch run changelog:entry
  • I used semantic commits (feat: will cause a major and fix: a minor version bump)
  • You can squash you commits, otherwise they will be squashed during merge

for change in snapshot._changes():
try:
change_list = list(snapshot._changes())
except Exception as exception:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To get even more, at least for Python 3.11+ (probably 80-90% of the users by now), you could use https://docs.python.org/3/library/exceptions.html#lib-exception-groups to collect even more details :-)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but ExceptionGroup is derived from Exception, which means that this code catches already ExceptionGroup. Or am I missing something here?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves error reporting when collecting snapshot changes (during show_report()), and adds tests to verify the new error output. It also extends the Example.run_inline() helper to support injecting additional context managers (used by the new tests).

Changes:

  • Wrap snapshot change collection in SnapshotSession.show_report() to raise a RuntimeError that includes snapshot expression + file/line.
  • Extend Example.run_inline() to accept extra context_managers for test-time patching.
  • Refactor/add tests to validate string-update output and the new change-collection error reporting (including Windows path normalization).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/utils.py Adds a reusable path_transform to normalize Windows path separators in snapshots.
tests/test_string.py Refactors string snapshot tests and introduces a helper fixture to reduce duplication.
tests/test_change_collection_error.py Adds coverage for the new error message when _changes() raises during report generation.
src/inline_snapshot/testing/_example.py Adds support for injecting context managers into inline example runs; adjusts exception handling/reporting behavior.
src/inline_snapshot/_types.py Adds typing for _expr on snapshot references.
src/inline_snapshot/_snapshot_session.py Adds error-wrapping around snapshot._changes() to improve diagnostics (file/line + snapshot repr).
src/inline_snapshot/_snapshot/undecided_value.py Removes change-generation logic for undecided values (now yields no changes by default).
src/inline_snapshot/_inline_snapshot.py Adds __repr__ for SnapshotReference and tightens AST typing with cast().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@15r10nk 15r10nk force-pushed the error-output branch 6 times, most recently from 3cfab45 to f70c0e6 Compare March 1, 2026 05:44
@15r10nk 15r10nk changed the title feat: improved error reporting UsageError("unmanaged values can not be compared with snapshots") when using -k flag #355 Mar 1, 2026
@15r10nk 15r10nk marked this pull request as ready for review March 1, 2026 06:08
@15r10nk 15r10nk merged commit e88e065 into main Mar 1, 2026
31 checks passed
@15r10nk 15r10nk deleted the error-output branch March 1, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants