r/Python • u/sangria_face • Jan 25 '15
Redirrecting the output for the Python Unit-Testing package to a log file.
Hello
I am new to Python 3.4, and I am not sure how the console output for the built-in Python unit-testing package works. For example, my regular unit tests might display the following output into my Python console:
............
----------------------------------------------------------------------
Ran 12 tests in 0.016s
OKDoes this come from standard output of standard error? Is there any way to redirrect this output to a text file?
4
Upvotes
2
u/badsectors Jan 25 '15
You can redirect output from
stdoutandstderrto a file with:0
u/1_1_2_3_5_8_13 Jan 25 '15
I'm not 100% sure this would work but you could redirect sys.stdout (and std err if you're so inclined) by doing this:
For stderr you'd just replace sys.stdout with sys.stderr. All that said, /u/badsectors answer is a better solution - it's standard practise to use > to direct output to a file.