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

Logging each test before running it #3878

Closed
Ezibenroc opened this issue Feb 11, 2024 · 1 comment
Closed

Logging each test before running it #3878

Ezibenroc opened this issue Feb 11, 2024 · 1 comment
Labels
question not sure it's a bug? questions welcome

Comments

@Ezibenroc
Copy link

Ezibenroc commented Feb 11, 2024

Hello,

I am using hypothesis for testing a python library that runs C code under the hood. Sometimes, the test crashes (e.g. with a segfault) and it is a pain to debug: I don't have the nice error output from hypothesis since the program terminated abruptly.

It would greatly help me to at least be able to reproduce the failure outside my test base, with a simple example. So, I thought about logging each test along with its parameters before the test is actually called. Is there an easy way to do that with hypothesis? I can always manually annotate all my tests, but that would be tedious.

@Zac-HD
Copy link
Member

Zac-HD commented Feb 12, 2024

https://hypothesis.readthedocs.io/en/latest/details.html#custom-function-execution

You can use .hypothesis.inner_test to apply a decorator "inside" @given() after the fact, which with Pytest hooks is a rather convenient way to add logging (or whatever other pre- and post-hooks you want) to all your tests.

Although note that you could instead use this to run the actual code-under-test in a freshly forked process each time, which would give you nice shrinking and so on as well by preventing it from tearing down the host process!

@Zac-HD Zac-HD closed this as completed Feb 12, 2024
@Zac-HD Zac-HD added the question not sure it's a bug? questions welcome label Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question not sure it's a bug? questions welcome
Projects
None yet
Development

No branches or pull requests

2 participants