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>2018-11-27 03:47:18 +0100
committerAmber Brown <hawkowl@atleastfornow.net>2018-11-27 13:47:18 +1100
commita44c0a096fbdca979cb47a3e7308cfe52be8d684 (patch)
tree78d54e17d6369fa1ed68d75405443793a2d8cc52 /tests/unittest.py
parentFix more logcontext leaks in tests (#4209) (diff)
downloadsynapse-a44c0a096fbdca979cb47a3e7308cfe52be8d684.tar.xz
Check logcontexts before and after each test (#4190)
* Add better diagnostics to flakey keyring test

* fix interpolation fail

* Check logcontexts before and after each test

* update changelog

* update changelog
Diffstat (limited to '')
-rw-r--r--tests/unittest.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/tests/unittest.py b/tests/unittest.py
index 2049187fd9..a191cccc29 100644
--- a/tests/unittest.py
+++ b/tests/unittest.py
@@ -102,8 +102,16 @@ class TestCase(unittest.TestCase):
             # traceback when a unit test exits leaving things on the reactor.
             twisted.internet.base.DelayedCall.debug = True
 
-            old_level = logging.getLogger().level
+            # if we're not starting in the sentinel logcontext, then to be honest
+            # all future bets are off.
+            if LoggingContext.current_context() is not LoggingContext.sentinel:
+                self.fail(
+                    "Test starting with non-sentinel logging context %s" % (
+                        LoggingContext.current_context(),
+                    )
+                )
 
+            old_level = logging.getLogger().level
             if old_level != level:
 
                 @around(self)
@@ -118,7 +126,6 @@ class TestCase(unittest.TestCase):
         @around(self)
         def tearDown(orig):
             ret = orig()
-
             # force a GC to workaround problems with deferreds leaking logcontexts when
             # they are GCed (see the logcontext docs)
             gc.collect()