Skip to content
Snippets Groups Projects
Commit ca8349a8 authored by Paul "LeoNerd" Evans's avatar Paul "LeoNerd" Evans
Browse files

Allow a TestCase to set a 'loglevel' attribute, which overrides the logging...

Allow a TestCase to set a 'loglevel' attribute, which overrides the logging level while that testcase runs
parent cd62ee3f
No related branches found
No related tags found
No related merge requests found
...@@ -27,4 +27,25 @@ logging.getLogger().setLevel(NEVER) ...@@ -27,4 +27,25 @@ logging.getLogger().setLevel(NEVER)
class TestCase(unittest.TestCase): 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment