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

Make accept_plugin viable, add a way to suppress assertions #57

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

untitaker
Copy link

@untitaker untitaker commented Jul 30, 2022

Hi, I think I found a very hacky way to suppress assertions and make the
assert_plugin viable to use.

Major changes:

  • doctest support temporarily removed (I just didn't need it myself and its
    tests seemed to leak test state in destructive ways)

  • the accept plugin doesn't rewrite non-literal RHS of assertions anymore. so for example assert 1 == 3 is rewritten, but assert 1 == complexlogic() isn't.

  • new '--accept-continue' flag that rewrites assertions to silently pass.

  • consolidate '--accept-copy' and '--accept' into one flag: '--accept=overwrite' and '--accept=new'

I also noticed that .new allows you to use insta to review things after running with --accept=new:

cargo insta review --workspace-root `pwd` -e py

I originally wanted to fork this plugin, and for simplicity get rid of doctest
support that I don't need, and adjust the API a bit as well. But I thought i'd
just push this up as PR for discussion, I don't think this can be merged as-is.

Most importantly, pytest-accept now relies on private pytest APIs. So in case
you want to adopt this hack, I would suggest to add a big fat disclaimer to the
README.

@untitaker untitaker changed the title Add a way to suppress assertions Make accept_plugin viable, add a way to suppress assertions Jul 30, 2022
@max-sixty
Copy link
Owner

@untitaker I'm very sorry indeed that I missed this — it must have got buried under my GH notifications. I came across it coincidentally when merging a PR from a bot! Apologies if it seemed that I wasn't interested — the opposite is true.

This is a very clever approach!! Congratulations for figuring it out.

Have you been using it? I'm quite up for integrating it in if it's been successful for you. Let me know and I'm happy to work on it to merge. (I'm less sure about --accept changing; I think almost always someone wants that given they're using version control, but I'm open-minded)

@untitaker
Copy link
Author

@max-sixty unfortunately I have not had the opportunity to use it so far. I'll let you know how it goes.

@ikonst
Copy link

ikonst commented Jan 13, 2023

@untitaker Pretty cool, agree we need the literal_eval check.

Given that pytest team hasn't necessarily been opposed to introducing a "continue on assert" mode, might be worth pursuing as a new mode for their assert plugin.

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