8

I am writing tests using pytest and if my validation fails it generates a lot of logs which is needed. I am using the python's standard logging module to log these errors to a file using FileHandler class. I am using pytest-html to generate the html report. Everything is working as expected except that pytest is logging the log messages into the terminal also which is taking more time than actual test execution. (Imagine logging around 200k log messages on the terminal).

Is there any option in pytest that would disable logging any logs into the terminal but still capture and make those logs available in the html report. It would still be desirable to log the exceptions or the assertion errors if possible.

2
  • 1
    pytest -p no:logging disables log capturing. Commented May 14, 2021 at 20:19
  • pytest -p no:logging is a good option when I need no logs in console or the pytest-html report. Unfortunately, this is not my current requirement. Thanks. Commented May 15, 2021 at 10:12

1 Answer 1

21

You might be able to configure the output using the --show-capture option.

From pytest --help:

--show-capture={no,stdout,stderr,log,all}
  Controls how captured stdout/stderr/log is shown on failed tests. Default is 'all'.

If you want a finer-grained control of what you filter out, you might need to look into the logging configuration itself (change the captured log level, etc.)

Sign up to request clarification or add additional context in comments.

1 Comment

I had to use the --show-capture=stdout. This does exactly what I wanted. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.