diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-08-02 16:13:33 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2012-08-02 16:13:33 +0000 |
commit | bcb424dd730a977aeaae9f6e33e9bb35cbc0c062 (patch) | |
tree | e691a2a0b3dd071826fb9c666f27b448b8fba30a /tests | |
parent | 1deed940ae115ab4ba23421efc6378feab0b62db (diff) | |
parent | 58404a1a9461900367dbb7a8b3f2f98441e12959 (diff) | |
download | oslo-bcb424dd730a977aeaae9f6e33e9bb35cbc0c062.tar.gz oslo-bcb424dd730a977aeaae9f6e33e9bb35cbc0c062.tar.xz oslo-bcb424dd730a977aeaae9f6e33e9bb35cbc0c062.zip |
Merge "Install a qualified except hook."
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_log.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/unit/test_log.py b/tests/unit/test_log.py index c4ce75b..35ff72d 100644 --- a/tests/unit/test_log.py +++ b/tests/unit/test_log.py @@ -1,7 +1,9 @@ import cStringIO import exceptions import logging +import subprocess import sys +import textwrap from openstack.common import context from openstack.common import cfg @@ -219,6 +221,31 @@ class LegacyFormatterTestCase(test_utils.BaseTestCase): self.assertEqual("NOCTXT: baz --DBG\n", self.stream.getvalue()) +class ExceptionLoggingTestCase(test_utils.BaseTestCase): + """Test that Exceptions are logged""" + + def test_excepthook_logs_exception(self): + code = textwrap.dedent(""" + import sys + from openstack.common import log as logging + + logging.setup('somename') + raise Exception('Some error happened') + """) + + child = subprocess.Popen([ + sys.executable, "-"], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + + (out, err) = child.communicate(input=code) + + self.assertTrue( + "CRITICAL somename [-] Some error happened", + msg="Exception is not logged") + + class FancyRecordTestCase(test_utils.BaseTestCase): """Test how we handle fancy record keys that are not in the base python logging""" |