diff options
author | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-09-12 18:29:07 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <paul@matrix.org> | 2014-09-12 18:46:13 +0100 |
commit | ca8349a897c233d72ea74128dabdd1311f00c13c (patch) | |
tree | b7039b887254cd2f4236d4d5e23d5e5221423c33 /tests/unittest.py | |
parent | Have all unit tests import from our own subclass of trial's unittest TestCase... (diff) | |
download | synapse-ca8349a897c233d72ea74128dabdd1311f00c13c.tar.xz |
Allow a TestCase to set a 'loglevel' attribute, which overrides the logging level while that testcase runs
Diffstat (limited to 'tests/unittest.py')
-rw-r--r-- | tests/unittest.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/tests/unittest.py b/tests/unittest.py index 00c3c532eb..19be03b96a 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -27,4 +27,25 @@ logging.getLogger().setLevel(NEVER) class TestCase(unittest.TestCase): - pass + def __init__(self, *args, **kwargs): + super(TestCase, self).__init__(*args, **kwargs) + + level = getattr(self, "loglevel", NEVER) + + orig_setUp = self.setUp + + def setUp(): + old_level = logging.getLogger().level + + if old_level != level: + orig_tearDown = self.tearDown + + def tearDown(): + ret = orig_tearDown() + logging.getLogger().setLevel(old_level) + return ret + self.tearDown = tearDown + + logging.getLogger().setLevel(level) + return orig_setUp() + self.setUp = setUp |