mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-21 17:15:38 +03:00
Allow a TestCase to set a 'loglevel' attribute, which overrides the logging level while that testcase runs
This commit is contained in:
parent
cd62ee3f29
commit
ca8349a897
1 changed files with 22 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue