Fix inline-snapshot compatibility#3506
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughRaises the inline-snapshot test dependency floor, updates the shared external-file assertion helper to use snapshot lookup with create/fix gating, and adds tests covering active, inactive, missing, and mismatched external snapshot files. ChangesInline-snapshot API compatibility update
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
📚 Docs Preview: https://pr-3506.datamodel-code-generator.pages.dev |
Merging this PR will improve performance by 10.13%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | WallTime | test_perf_graphql_style_pydantic_v2 |
827 ms | 751 ms | +10.13% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix-inline-snapshot-compat (bfc24d6) with main (cb192dd)
Footnotes
-
98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3506 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 153 153
Lines 33755 33896 +141
Branches 3958 3967 +9
==========================================
+ Hits 33755 33896 +141
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c5f6c5f to
149e46b
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/conftest.py (2)
614-650: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOptional: deduplicate the mismatch error construction.
The
hint/diff/msg/raiseblock at Lines 618-621 (string branch) and Lines 647-650 (non-string branch) is identical. Extracting a small local helper would reduce repetition.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/conftest.py` around lines 614 - 650, The mismatch error construction is duplicated in both the string and non-string branches of the snapshot assertion logic, so factor the shared hint/diff/msg/raise sequence into a small local helper inside the snapshot comparison flow. Keep the existing behavior in the function that handles normalized content and expected values, and reuse the helper from both branches to avoid repeating the same error-building code.
630-646: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
assertused for the inline-snapshot recording side effect is fragile underpython -O.Lines 633 and 645 rely on
expected == normalized_contentto trigger inline-snapshot's__eq__materialization in create/fix mode, then wrap it inassert. When tests run withpython -O(orPYTHONOPTIMIZE),assertstatements are stripped, so the comparison never executes and missing/mismatched external files would silently not be created/updated. Consider executing the comparison as a plain statement (and asserting on a captured result if you still want the check).♻️ Suggested change
- if update_flags.create: - # Let inline-snapshot materialize missing external files only in create mode. - assert expected == normalized_content - return + if update_flags.create: + # Let inline-snapshot materialize missing external files only in create mode. + matched = expected == normalized_content + assert matched + return(and likewise for the fix-mode branch at Line 645)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/conftest.py` around lines 630 - 646, The create/fix branches in the inline-snapshot handling rely on an `assert` to trigger `expected == normalized_content`, but that side effect is stripped under optimized Python runs. Update the logic in the snapshot comparison block to execute the equality comparison as a plain statement in both the create-mode and fix-mode paths, using the existing `expected`, `normalized_content`, `update_flags.create`, and `update_flags.fix` flow; if you still need a validation check, capture the comparison result separately instead of depending on `assert`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/conftest.py`:
- Around line 614-650: The mismatch error construction is duplicated in both the
string and non-string branches of the snapshot assertion logic, so factor the
shared hint/diff/msg/raise sequence into a small local helper inside the
snapshot comparison flow. Keep the existing behavior in the function that
handles normalized content and expected values, and reuse the helper from both
branches to avoid repeating the same error-building code.
- Around line 630-646: The create/fix branches in the inline-snapshot handling
rely on an `assert` to trigger `expected == normalized_content`, but that side
effect is stripped under optimized Python runs. Update the logic in the snapshot
comparison block to execute the equality comparison as a plain statement in both
the create-mode and fix-mode paths, using the existing `expected`,
`normalized_content`, `update_flags.create`, and `update_flags.fix` flow; if you
still need a validation check, capture the comparison result separately instead
of depending on `assert`.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: b057567c-359c-4c39-8d18-a9dabe022767
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock,!**/*.lockand included by none
📒 Files selected for processing (3)
pyproject.tomltests/conftest.pytests/test_conftest_helpers.py
149e46b to
a583915
Compare
a583915 to
bfc24d6
Compare
Breaking Change AnalysisResult: No breaking changes detected Reasoning: The PR only modifies test infrastructure: it bumps the This analysis was performed by Claude Code Action |
|
🎉 Released in 0.66.1 This PR is now available in the latest release. See the release notes for details. |
Fixes: #3505
Summary by CodeRabbit