-
Notifications
You must be signed in to change notification settings - Fork 102
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
Don't allow missing snapshots without --snapshot-update #112
base: master
Are you sure you want to change the base?
Don't allow missing snapshots without --snapshot-update #112
Conversation
Why not add a command line flag to enable it (disabled by default) so you can ship this in a minor version? Then, you can have that flag enabled by default in the next major version. |
Yeah, I suspect something like that is the way to do it. Unfortunately this repository seems to be unmaintained. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for this! I just got write access to the repo. I left you a comment.
snapshottest/module.py
Outdated
@@ -231,16 +242,19 @@ def assert_value_matches_snapshot(self, test_value, snapshot_value): | |||
def assert_equals(self, value, snapshot): | |||
assert value == snapshot | |||
|
|||
def assert_match(self, value, name=''): | |||
def assert_match(self, value, name="", update=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I call assert_match(..., update=False)
I would expect no updates to happen, but if self.update
is set that would take precedence. This is a bit confusing.
What is the purpose of this parameter? Is it intended only for testing?
If so, I wonder if it would be better for tests to manipulate the .update
property, rather than add a parameter to this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote this a while ago, but yeah I think it's only used in tests. I think I did it this way because adding self.update = True
and self.update = False
around every test is a lot of boilerplate (it's as many lines of boilerplate as are in most of the tests in the first place).
I definitely agree that it's confusing though. For now I'll rename it to _force_update_snapshots
, if you think that's ok then you can merge, or if not we can try to think of something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I did it this way because adding
self.update = True
andself.update = False
around every test is a lot of boilerplate (it's as many lines of boilerplate as are in most of the tests in the first place).
Does it need to be set back to False
? I wouldn't think so. Though if it does, what about using a context handler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had another look: the reason I didn't do it that way was actually because update was a getter function and had some interactions with different testing frameworks that I didn't really understand.
I've pushed a commit with a refactoring that turns it into a plain member variable, and then sets that variable. I think the code is cleaner but I'm less confident that it will work correctly with all supported testing frameworks because I'm not sure I fully understand what the code was doing before (and I don't have anywhere to test django or nose other than the unit tests).
Up to you whether we merge with or without the refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we probably need to rely on the unit tests, or improve them if they aren't covering the behavior they need to.
What do you imagine might break?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried about "unknown unknowns" because I don't know what I need to worry about with those frameworks (in my experience test frameworks sometimes have magical behaviour, so things can look like they should work but not work).
I think it's probably fine, but maybe we can do an rc or beta build first and get people who are using those frameworks to try it out? Or maybe you're right and we should just trust the unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Let's plan on shipping a bunch of betas until we have tackled all the breaking changes in a release that we've given the community at least a couple weeks to validate.
@paulmelnikow Do you think it's worth adding a command line flag to control this behaviour? I feel like this should be the default behaviour ASAP because the old version could cause spurious test passes. So I think it would be reasonable to release a new major version now-ish with no breaking changes other than this. If we do that then I think there's no need to add a flag and immediately deprecate it because anyone who wants to opt-in to the new behaviour can upgrade and anyone who doesn't want it right now can not upgrade. |
I feel strongly that this the current behavior is incorrect and dangerous. Until someone articulates an important use case for the flag (that can't be worked around easily) I think we should not provide a flag. I think this is a bug fix, but agreed it is a major enough change in behavior that it should be called a breaking change. I feel a lot of urgency about fixing this too; just want to do so with care 😀 Once we get it in good shape I think we can merge it and set the version number accordingly. |
I'm a bit confused about why |
cfb2d10
to
2036522
Compare
Oh yeah, I didn't notice that there was a I also rebased onto the black commit by running black on my own branch, squashing my branch, and rebasing (merging normally was a complete mess). I think it's done something sensible. |
(Also closes #25, I think) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, though I’d like to try it out a little bit before we merge it. @medmunds could you review, too? We also need to update the documentation.
tests/test_formatter.py and tests/test_sorted_dict.py seem to have been reformatted without any other changes, and should probably be omitted from this PR. Other than that, looks good to me. (And much easier to follow the should_update logic across the different frameworks now!) |
@paulmelnikow @davidshepherd7 it would be awesome to get this merged. Anything I can do to help here? |
IIRC the code is all ready to go and it just needs someone to merge it.
…On Thu, 13 May 2021, 19:44 Kenneth Skovhus, ***@***.***> wrote:
@paulmelnikow <https://github.com/paulmelnikow> @davidshepherd7
<https://github.com/davidshepherd7> it would be awesome to get this
merged. Anything I can do to help here?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#112 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGCJVFDVW2M5SQAOSOGMFDTNQMX5ANCNFSM4KVX43FA>
.
|
It would make sense to merge and just release as part of the 1.0 beta. |
Where are we on merging this ?? Hit this issue a couple of times. |
Any updates here? This is a major problem for bigger projects. |
Fixes #73
Possibly should only be included in a new major version so that it doesn't break people's CI.