This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brett.cannon
Recipients alex, brett.cannon, ncoghlan, rhettinger
Date 2012-08-29.17:16:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
So Alex's point is valid: the examples in the unittest.mock.patch docs shows how to do this ( 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.
Date User Action Args
2012-08-29 17:16:39brett.cannonsetrecipients: + brett.cannon, rhettinger, ncoghlan, alex
2012-08-29 17:16:39brett.cannonsetmessageid: <>
2012-08-29 17:16:39brett.cannonlinkissue15805 messages
2012-08-29 17:16:38brett.cannoncreate