Code review comment for lp:~jml/testtools/patch-310770

Revision history for this message
Robert Collins (lifeless) wrote :

A few thoughts.

Firstly, I'd expect this to delete an attribute too, if the original
was unset; this doesn't, but the tests don't make it clear whether
that is oversight or intent.

Secondly, this is so useful, I really would rather not see it on TestCase.

How about

def patch(obj, attribute, value):
    """Set obj.attribute to value and return a cleanup to restore it."""

?

Then you can do
self.addCleanup(patch(sys, "stderr", StringIO())

« Back to merge proposal