Python 2.7 Python:日志记录有问题。错误(traceback.format\u异常)

Python 2.7 Python:日志记录有问题。错误(traceback.format\u异常),python-2.7,python-3.6,python-unittest,Python 2.7,Python 3.6,Python Unittest,我有以下代码: def tearDown(self): e_type, e_value, tb = sys.exc_info() if e_type is not None: logging.error((traceback.format_exception(e_type, e_value, tb))) 当我使用Python 2.7时,一切正常,但升级到3.6版后,它就不再工作了: 例如,我创建了一些用于测试的示例,我希望出现错误 def test_creat

我有以下代码:

 def tearDown(self):
    e_type, e_value, tb = sys.exc_info()
    if e_type is not None:
        logging.error((traceback.format_exception(e_type, e_value, tb)))
当我使用Python 2.7时,一切正常,但升级到3.6版后,它就不再工作了:

例如,我创建了一些用于测试的示例,我希望出现错误

def test_create_new_user_without_all_fields1(self):
    self.assertEqual('USER_1', 'USER_2')
    logging.info('test_create_new_user_without_all_fields1: Passed')
控制台中的结果:

======================================================================
FAIL: test_create_new_user_without_all_fields1 (test_testExample.BaseTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Dev\git\CST\tests\test_testExample.py", line 16, in test_create_new_user_without_all_fields1
    self.assertEqual('USER_1', 'USER_2')
AssertionError: 'USER_1' != 'USER_2'
- USER_1
+ USER_2
?  +
让我们将小字体添加到拆卸:

print (sys.exc_info())
结果:

(None, None, None)
正如我们所看到的,已经没有例外了,但应该如此。如何解决这个问题

e_type, e_value, tb = self._outcome.errors[1][1]
logging.error(''.join(traceback.format_exception(e_type, e_value, tb)))