Brett Cannon added the comment:

So Alex's point is valid: the examples in the unittest.mock.patch docs shows 
how to do this 
(http://docs.python.org/dev/py3k/library/unittest.mock.html#patch). So this 
could be simplified to:

def redirect_stdout(replacement=None):
  return unittest.mock.patch('sys.stdout', replacement if replacement is not 
None else io.StringIO())

Now that being said, this is extremely common, so Nick's point of just going 
ahead and providing the helper makes sense. But I wouldn't put it in contextlib 
but instead in unittest.mock since it is mocking out sys.stdout.

----------
nosy: +brett.cannon

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15805>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to