-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.py
42 lines (30 loc) · 813 Bytes
/
error.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
#
# lhq
#
import StringIO
import logging
import traceback
def trace_log():
fp = StringIO.StringIO()
traceback.print_exc(file=fp)
logging.error(fp.getvalue())
def trace_msg():
fp = StringIO.StringIO()
traceback.print_exc(file=fp)
return fp.getvalue()
if __name__ == '__main__':
import unittest
from testException import TestException
class MyTest(unittest.TestCase):
def test_trace_log(self):
try:
raise TestException("test")
except TestException:
self.assertIsNone(trace_log())
def test_trace_msg(self):
try:
raise TestException("test")
except TestException:
self.assertIsNotNone(trace_msg())
unittest.main()