2 回答

TA贡献1796条经验 获得超10个赞
你还在使用 Python 2.x 有什么理由吗?如果您切换到 Python 3.x,则异常将以您期望的方式显示。
$ python3 t.py
F
======================================================================
FAIL: test_string_matches (__main__.Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "t.py", line 7, in test_string_matches
self.assertEqual(u'你好', u'好')
AssertionError: '你好' != '好'
- 你好
? -
+ 好
----------------------------------------------------------------------
Ran 1 test in 0.000s
FAILED (failures=1)

TA贡献1843条经验 获得超7个赞
如果您需要在 Python2 上使用它,我发现解决问题的唯一方法是强制系统的编码为utf-8:
reload(sys)
sys.setdefaultencoding('utf-8')
添加回答
举报