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

fix: support call syntax for snapshot fixture overriding #160

Merged
merged 6 commits into from
Mar 24, 2020
Merged

Conversation

iamogbz
Copy link
Collaborator

@iamogbz iamogbz commented Mar 21, 2020

Description

Support call syntax to easily switch extension class

Related Issues

N/A

Checklist

  • This PR has sufficient test coverage.
  • I will merge this pull request with a semantic title.

Additional Comments

No additional comments.

@iamogbz iamogbz requested a review from noahnu March 21, 2020 00:27
@codecov
Copy link

codecov bot commented Mar 21, 2020

Codecov Report

Merging #160 into master will not change coverage by %.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #160   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines          841       859   +18     
=========================================
+ Hits           841       859   +18     

@iamogbz iamogbz changed the title feat: support call syntax for snapshot fixture overriding fix: support call syntax for snapshot fixture overriding Mar 21, 2020
@iamogbz
Copy link
Collaborator Author

iamogbz commented Mar 21, 2020

@noahnu using fix: in order to trigger a patch release and not a minor version bump

@iamogbz iamogbz added the feature request New feature or request label Mar 21, 2020
)
assert snapshot_svg == actual_svg
assert actual_svg == snapshot(extension_class=SVGImageSnapshotExtension)
assert actual_svg == snapshot # last extension class specified is used
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like that behaviour can be confusing. Perhaps it should function similar to snapshot.use_extension, where it effectively clones the snapshot instance

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If it clones it then it'll lose the context of assertion index, leading to duplicates

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can clone assertion index. I find it strange that calling snapshot at the beginning of a test case can affect snapshot assertions towards the end of the test case. Strange side-effects

Copy link
Collaborator Author

@iamogbz iamogbz Mar 21, 2020

Choose a reason for hiding this comment

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

@noahnu so your preferred behaviour would be having this line use the default snapshot extension class? It does make it more "pure" but then requires a lot of cloning of state values. Since the snapshot fixture is bound to the test case function the limit of the side effects would only be in specific test, I don't think that's too confusing and it would allow for doing stuff like #161 without a lot of copying.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@noahnu also I don't think we could track with cloning assertion index if each individual assertion in the test case is a new instance

@iamogbz iamogbz requested a review from noahnu March 21, 2020 12:14
)
assert snapshot_svg == actual_svg
assert actual_svg == snapshot(extension_class=SVGImageSnapshotExtension)
assert actual_svg == snapshot # uses initial extension class
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@noahnu changed, so that the initial extension class is used when not overridden

src/syrupy/assertion.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@noahnu noahnu left a comment

Choose a reason for hiding this comment

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

LGTM

@iamogbz iamogbz merged commit 4cf051c into master Mar 24, 2020
@iamogbz iamogbz deleted the call-syntax branch March 24, 2020 23:36
syrupy-bot pushed a commit that referenced this pull request Mar 24, 2020
## [0.3.7](v0.3.6...v0.3.7) (2020-03-24)

### Bug Fixes

* support call syntax for snapshot fixture overriding ([#160](#160)) ([4cf051c](4cf051c))
@syrupy-bot
Copy link
Contributor

🎉 This PR is included in version 0.3.7 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants