PyDev unittesting: How to capture text logged to a logging.Logger in "Captured Output"
By : user3549417
Date : March 29 2020, 07:55 AM
should help you out The issue is that the unittest runner replaces sys.stdout/sys.stderr before the testing starts, and the StreamHandler is still writing to the original sys.stdout. If you assign the 'current' sys.stdout to the handler, it should work (see the code below).
I hope this helps . In your googletest suite, you can use the boost::log facilities in each test case to redirect the BOOST_LOG_TRIVIAL messages to a file. After writing the BOOST_LOG_TRIVIAL message(s) you want you can then flush the file, open it, and check that it has the contents you expect. For example: gtester.cpp
[==========] Running 2 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 2 tests from boost_log_tester
[ RUN ] boost_log_tester.info_msg
[ OK ] boost_log_tester.info_msg (0 ms)
[ RUN ] boost_log_tester.error_msg
[ OK ] boost_log_tester.error_msg (2 ms)
[----------] 2 tests from boost_log_tester (2 ms total)
[----------] Global test environment tear-down
[==========] 2 tests from 1 test case ran. (2 ms total)
[ PASSED ] 2 tests.