Message169400
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. |
|
Date |
User |
Action |
Args |
2012-08-29 17:16:39 | brett.cannon | set | recipients:
+ brett.cannon, rhettinger, ncoghlan, alex |
2012-08-29 17:16:39 | brett.cannon | set | messageid: <1346260599.65.0.190822585501.issue15805@psf.upfronthosting.co.za> |
2012-08-29 17:16:39 | brett.cannon | link | issue15805 messages |
2012-08-29 17:16:38 | brett.cannon | create | |
|