summary refs log tree commit diff
path: root/tests/unittest.py
diff options
context:
space:
mode:
authorRichard van der Hoff <1389908+richvdh@users.noreply.github.com>2020-09-28 17:58:33 +0100
committerGitHub <noreply@github.com>2020-09-28 17:58:33 +0100
commit5e3ca12b158b4abefe2e3a54259ab5255dca93d8 (patch)
treefffcae603f7af4ac05b7d344667a481811bf153f /tests/unittest.py
parentAdd `ui_auth_sessions_ips` table to `synapse_port_db` ignore list (#8410) (diff)
downloadsynapse-5e3ca12b158b4abefe2e3a54259ab5255dca93d8.tar.xz
Create a mechanism for marking tests "logcontext clean" (#8399)
Diffstat (limited to 'tests/unittest.py')
-rw-r--r--tests/unittest.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/unittest.py b/tests/unittest.py
index dabf69cff4..bbe50c3851 100644
--- a/tests/unittest.py
+++ b/tests/unittest.py
@@ -23,7 +23,7 @@ import logging
 import time
 from typing import Optional, Tuple, Type, TypeVar, Union
 
-from mock import Mock
+from mock import Mock, patch
 
 from canonicaljson import json
 
@@ -169,6 +169,19 @@ def INFO(target):
     return target
 
 
+def logcontext_clean(target):
+    """A decorator which marks the TestCase or method as 'logcontext_clean'
+
+    ... ie, any logcontext errors should cause a test failure
+    """
+
+    def logcontext_error(msg):
+        raise AssertionError("logcontext error: %s" % (msg))
+
+    patcher = patch("synapse.logging.context.logcontext_error", new=logcontext_error)
+    return patcher(target)
+
+
 class HomeserverTestCase(TestCase):
     """
     A base TestCase that reduces boilerplate for HomeServer-using test cases.