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

Can we consider optionally disabling automatic repr-printing and jsonification when TESTCASE_CALLBACKS are present? #3880

Closed
joshuafcole opened this issue Feb 12, 2024 · 2 comments · Fixed by #3882

Comments

@joshuafcole
Copy link
Contributor

joshuafcole commented Feb 12, 2024

Thanks for Hypothesis, it's awesome!

I have a REPL set up for continuously testing the program I'm working on using some hypothesis tests. The inputs are fairly large dataclasses that are unfortunately self-referential.

This works well in general, but when I attempt to tap result generation via a callable in TESTCASE_CALLBACKS, things slow down or crash due to blowing the stack. I have my own pretty-printers that I'd like to call from the repl experience, so I don't have any use for the jsonable or pprinted inputs. I checked over the code to see if I could find a flag to override the behavior (or return my own value for either) but I couldn't find any reasonable solution.

Would you be willing to consider making that behavior optionable via a flag or bump the to_json check earlier in the to_jsonable resolution chain?

I'd be happy to patch it to save you the time if a solution jumps out at you as a good one.

Thanks!
Josh

to_jsonable

only attempts user-configurable to_json if all else fails

impossible to prevent jsonification when TESTCASE_CALLBACKS are present

@Zac-HD
Copy link
Member

Zac-HD commented Feb 13, 2024

I'd prefer not to add another config option, but would be happy to shift the .to_json() check to before the attrs/dataclasses/pydantic block in to_jsonable(). PR welcome for that!

You can also improve the interaction with pretty-printing downstream; we support the IPython protocol and/or you can shove a callback directly into the registry if you'd prefer.

@joshuafcole
Copy link
Contributor Author

I'd prefer not to add another config option

Understandable!

happy to shift the .to_json() check to before the attrs/dataclasses/pydantic block in to_jsonable(). PR welcome for that!

Sure thing, I'll get one cooking today!

You can also improve the interaction with pretty-printing downstream; we support the IPython protocol and/or you can shove a callback directly into the registry if you'd prefer.

That's a solid idea, thanks!

joshuafcole added a commit to joshuafcole/hypothesis that referenced this issue Feb 14, 2024
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 a pull request may close this issue.

2 participants