Message169400
| 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 |
<1346260599.65.0.190822585501.issue15805@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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. |
|
History
|
|---|
| 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 |
|