pytest does not capture print() statements (stdout output) which are located in pytest_sessionfinish() or code which is called in there. What's best practice to get same or similar behavior like print() statements located in tests, fixtures, etc.?

# conftest.py def pytest_sessionfinish(session, exitstatus): print('This wont be captured (like in tests) but output independent of pytest exit status (exitstatus).') if exitstatus == 0: print('stdout shall be captured/suppressed in case of overall test PASS.') else: print('stdout shall be output in case of overall test FAIL and any other error.') 
5

Related questions 255 Logging within pytest tests 856 How to see normal print output created during pytest run? 3 pytest capturing all output to stdout Related questions 255 Logging within pytest tests 856 How to see normal print output created during pytest run? 3 pytest capturing all output to stdout 3 Access pytest session or arguments in pytest_runtest_logreport 6 pytest option to output print/logging statements from tested code 3 pytest_sessionstart/finish won't print 2 passing variable to pytest_sessionfinish 2 How to capture print statements inside pytest hooks 2 Pytest capture stdout of a certain test 1 pytest_sessionstart/finish show AttributeError: 'Session' object has no attribute 'results' Load 7 more related questions Show fewer related questions

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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