-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
New function with simpler API #62
Comments
What do you mean here? Is there currently any risk that tests pass because of inline-snapshot?
"update if needed" ... I don't understand how you would do it in your proposal. I'm currently working on #63 which allows you to run I have no experience with PyCharm, but I want to try it to see how it works with inline-snapshot. I hope this allows me to understand your workflow and your problems better. |
Not currently, unless someone uses
i.e. the proposal here would mean that snapshots are always fixed but tests don't always pass, so it's both convenient and safe.
I just mean they wouldn't be updated if they were already correct.
Here's what I mean by running a test with two clicks:
This is way more convenient (and faster) than running I basically want to still do just that and also see the test code update without further interaction.
As I said in #48 (comment), I actually prefer to just apply the changes and review them after. |
but the tests will pass in the next pytest run if they are fixed, right? |
Right. |
And how would you debug test which fail because you broke something (where you don't want to change the snapshots)? would you use pytest with an argument like I fix my bugs more often then I change my snapshots and this solution would make my normal workflow more complicated. |
I don't need to avoid changing the snapshot. A change in the snapshot is a visible change that's often easier to inspect than the diff from a test failure. If I didn't expect a change, then I fix the function and rerun the test until the change disappears. Basically I do the same thing I would do without inline-snapshot. |
Ahh, you are basically ignoring the pytest errors (almost) and rely more on the diff. changes in the diff mean you broke something. I don't think that I would recommend this for everyone, but I think I could provide a config option which defines default "mode" which inline-snapshot uses. I will think about it while I'm working on #63. Maybe there are more options which would be useful as a default. You should be able to hack it into some branch and try it yourself for now. How important is it for you that you have a |
It's not essential. An alternative way to achieve similar results would be to:
Then I would turn on that first flag and |
I agree that we definitely need a flag to raise an error if the expected value does not match the actual one. For me, the most intuitive default scenario for inline snapshots would be to use this flag along with In cases where only @repr_wrapper
def snapshot(obj=undefined):
...
if not _active:
if obj is undefined:
raise AssertionError(
"your snapshot is missing a value run pytest with --inline-snapshot=create"
)
else:
return
# < --- new
if obj is not undefined and not _update_flags.update and not _update_flags.fix and not _update_flags.trim:
return obj
# >
... |
something similar will become part of #63. No flag will affect the outcome of your tests.
|
Here's a proposal for what I think my ideal API/workflow would look like. Hopefully if you don't like all of it you can still extract some good ideas.
When the second argument doesn't exist or doesn't equal the first:
--inline-snapshot=fix/create/update
or any other configuration, it's just the default behaviour.Reasoning:
assert
means thatexecuting
works fine without needing to disable pytest rewriting, fulfilling the desire in Allow fixing snapshots without disabling pytest rewriting #57.inline_snapshot
.--inline-snapshot=fix
is by associating that with whole files where I expect to reuse that configuration, but it becomes less practical for a single test function.assert
,==
andshot
vs just,
.The text was updated successfully, but these errors were encountered: