summaryrefslogtreecommitdiff
path: root/searx/testing.py
diff options
context:
space:
mode:
Diffstat (limited to 'searx/testing.py')
-rw-r--r--searx/testing.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/searx/testing.py b/searx/testing.py
index 08a53e3f4..a3616dc12 100644
--- a/searx/testing.py
+++ b/searx/testing.py
@@ -80,6 +80,18 @@ class SearxTestCase(TestCase):
layer = SearxTestLayer
+ def setattr4test(self, obj, attr, value):
+ """
+ setattr(obj, attr, value)
+ but reset to the previous value in the cleanup.
+ """
+ previous_value = getattr(obj, attr)
+
+ def cleanup_patch():
+ setattr(obj, attr, previous_value)
+ self.addCleanup(cleanup_patch)
+ setattr(obj, attr, value)
+
if __name__ == '__main__':
import sys