[Tutor] redirecting testing output to file, using two different options

Mats Wichmann mats at wichmann.us
Wed May 16 14:48:37 EDT 2018

On 05/16/2018 02:53 AM, Yosef Levy wrote:
> Hello All,
> I have testing environment.
> Code is written under Python 2.6.

Why? 2.6 was retired in October 2013.  For long life of your code you
should be using Python 3, but at least 2.7 is still current and getting
updates (for another 18 months or so).

> testing output should be redirected to log file.
> I am using two different file handling, in order to log output:
> 1. logging module:

> 2. but if I want to redirect assert messages to file, I have to:
> import unittest2

> Question:
> Is the a way to 'merge' the above two different ways output to file?
> Or, is there a way to redirect assert messages to logging module methods?

If you use pytest, this should be fairly straightforward. It normally
captures stdout and stderr (the latter should have your asserts), and
with a plugin, puts logging output on the same basis, so you get get
everything going the same place:


More information about the Tutor mailing list