Author vinay.sajip
Recipients hpk, srid, vinay.sajip
Date 2009-07-10.08:00:00
SpamBayes Score 3.89498e-09
Marked as misclassified No
Message-id <>
> Are you suggesting that the ownership of `sys.stderr` belongs to the
> logging module once logging.basicConfig (that initializes a 
> StreamHandler with stderr) is called?
> That no other module/library is to close sys.stderr even though they
> created it (sys.__stderr__ being the backup)?

> StreamHandler can take ownership of an arbitrary stream (say, created
> by the caller) passed to it, but assuming ownership of a
> standard stream, that are free to be overridden by a library (such as
> py.test), is rather bizarre.

Actually, it's not bizarre at all. Are you saying it's OK for multiple
threads in a program to write to sys.stderr, whenever they want, without
restriction, even if the end result is end-user visible output which is
gibberish (for example data from two logical streams interspersed
randomly)? Just because it's a "standard" stream? 

Also, perhaps you haven't noticed that StreamHandler has no way of
knowing whether the stream it was passed was a standard stream or not.
Logging may make certain hasattr-type checks e.g. for presence of
"flush" or "close", but it can't expect to not have ownership of the
stream, even for a standard stream.

I advise you to do the following: refactor your test cases to include
the explicit handler-adding code in your setup (instead of basicConfig),
and the handler-removing and closing code in your teardown.

def setUp(self):
  self.hdlr = logging.StreamHandler(stream)

def tearDown(self):

where I have given someLogger module scope in the above snippet, you may
of course make it a testcase attribute too.

No changes to py.test are required. What happens if you do this?
Date User Action Args
2009-07-10 08:01:29vinay.sajipunlinkissue6333 messages
2009-07-10 08:00:04vinay.sajipsetrecipients: + vinay.sajip, srid, hpk
2009-07-10 08:00:04vinay.sajipsetmessageid: <>
2009-07-10 08:00:02vinay.sajiplinkissue6333 messages
2009-07-10 08:00:00vinay.sajipcreate