summaryrefslogtreecommitdiff
path: root/passlib/tests/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'passlib/tests/utils.py')
-rw-r--r--passlib/tests/utils.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py
index 29254c8..2965689 100644
--- a/passlib/tests/utils.py
+++ b/passlib/tests/utils.py
@@ -203,6 +203,22 @@ def quicksleep(delay):
#=============================================================================
# custom test harness
#=============================================================================
+
+def patchAttr(test, obj, attr, value):
+ """monkeypatch object value, restoring original on cleanup"""
+ try:
+ orig = getattr(obj, attr)
+ except AttributeError:
+ def cleanup():
+ try:
+ delattr(obj, attr)
+ except AttributeError:
+ pass
+ test.addCleanup(cleanup)
+ else:
+ test.addCleanup(setattr, obj, attr, orig)
+ setattr(obj, attr, value)
+
class TestCase(_TestCase):
"""passlib-specific test case class