Merge lp:~jml/testtools/patch-310770 into lp:~testtools-committers/testtools/trunk
Proposed by
Jonathan Lange
Status: | Merged |
---|---|
Merged at revision: | 89 |
Proposed branch: | lp:~jml/testtools/patch-310770 |
Merge into: | lp:~testtools-committers/testtools/trunk |
Diff against target: | 0 lines |
To merge this branch: | bzr merge lp:~jml/testtools/patch-310770 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
testtools developers | Pending | ||
Review via email: mp+31666@code.launchpad.net |
Description of the change
More and more I've found myself wanting to monkey-patch code with testtools in the same way I can for Trial. This branch adds support for just such a thing.
To post a comment you must log in.
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 (patch( sys, "stderr", StringIO())
self.addCleanup