[py-dev] Issue with py.test and stderr

Armin Rigo arigo at tunes.org
Mon Jan 17 11:21:19 CET 2005


Hi Grig,

On Fri, Jan 14, 2005 at 11:56:48AM -0800, Grig Gheorghiu wrote:
> I did run into a slight issue though. At some point I was instantiating
> a class which was redirecting stderr to stdout under some
> circumstances. The __del__ method of my class was resetting sys.stderr
> to sys.__stderr__.

Note that there is support in py.test for clean setup/teardown semantics, i.e.
instead of using __del__ (which is not guaranteed to run timely) you should
save and restore sys.stderr in setup/teardown methods; e.g.:

def setup_module(mod):
    mod.saved_stderr = sys.stderr
    sys.stderr = ...something else...

def teardown_module(mod):
    sys.stderr = mod.saved_stderr


Armin



More information about the Pytest-dev mailing list