I found the below code here on stackoverflow in order to write my python unittest results to a text file. Per the python unittest documentation the first argument in unittest.TextTestRunner
is the stream. So, f
which represents the text file is where the output goes. When I run this I see that the console no longer displays the output. How can I get the unittest results to display in both the console AND the text file at the same time? Thank you very much.
log_file = 'log_file.txt'
with open(log_file, "w") as f:
runner = unittest.TextTestRunner(f, verbosity=2)
unittest.main(testRunner=runner)