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 does not fully work in pytest #344

Open
olevski opened this issue Aug 6, 2024 · 0 comments
Open

Logging does not fully work in pytest #344

olevski opened this issue Aug 6, 2024 · 0 comments

Comments

@olevski
Copy link
Member

olevski commented Aug 6, 2024

If we use the python logging module or the sanic logger (which is just using the python logging module too), then when an error occurs during the running of a test the logs from it are not shown at all by pytest.

We saw this when schemathesis caused a failure that resulted in a 500 but when the test finishes the logs that pytest captured does not show anything and you cannot see or troubleshoot the problem.

To reproduce:

  • pick an endpoint
  • raise a random error (i.e. ValueError or KeyError)
  • run schemathesis to test this endpoint
  • schemathesis will fail because in all cases the endpoint will return 500 but the logs from pytest will not show anything even though the error handler should log the unhandled/unexpected exception

To remediate this we added a conditional print statement that prints the exception - and this shows up in pytest. But it should be that the logging module should simply work in this case.

What I tried to do to fix this is try to flush all logs before the server shuts down, or even try to flush all logs right after the exception handler printed the exception. But I could never get the error to show up in the logs when running pytest.

@olevski olevski changed the title Logging does not work in pytest Logging does not fully work in pytest Aug 6, 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

No branches or pull requests

1 participant