【发布时间】:2013-12-05 20:10:40
【问题描述】:
嗨,我想知道是否有办法修复鼻子测试断言失败的输出。我有一个名为“t.py”的简单脚本:
import unittest
from nose.tools import assert_equal
class x(unittest.TestCase):
"""
Testing
"""
def test(self):
assert_equal(1, 2)
如果我使用命令“nosetests t”运行它,那么我会得到以下结果。
AssertionError: 1 != 2
'1 != 2' = '%s != %s' % (safe_repr(1), safe_repr(2))
'1 != 2' = self._formatMessage('1 != 2', '1 != 2')
>> raise self.failureException('1 != 2')
而不是运行“python -m unittest t”时得到的输出
AssertionError: 1 != 2
有谁知道我如何使鼻子测试输出与单元测试输出匹配?当运行许多测试时,这会使结果混乱。
这是使用 python 2.7.3,nose==1.3.0,在 ubuntu VM 内的 virtualenv 中。
编辑:
我对 Nose 尝试提供更多信息没有意见。我有一个不断增长的测试套件,额外的信息可能会有所帮助。只是它提供了相当无用的信息。我真的不需要多次查看相同的信息。如果有多个测试,或者特别是如果有如下附加消息,则很难发现问题:
assert_equal(1,2, "Something is messed up before this assertion. Now here is a bunch of info to help with debugging. This is really quite a lot of info you know. Yes it is very long isn't it?")
然后我明白了:
assert_equal(1,2, "Something is messed up before this assertion. Now here is a bunch of info to help with debugging. This is really quite a lot of info you know. Yes it is very long isnt it?")
AssertionError: Something is messed up before this assertion. Now here is a bunch of info to help with debugging. This is really quite a lot of info you know. Yes it is very long isn't it?
'1 != 2' = '%s != %s' % (safe_repr(1), safe_repr(2))
"Something is messed up before this assertion. Now here is a bunch of info to help with debugging. This is really quite a lot of info you know. Yes it is very long isnt it?" = self._formatMessage("Something is messed up before this assertion. Now here is a bunch of info to help with debugging. This is really quite a lot of info you know. Yes it is very long isnt it?", '1 != 2')
>> raise self.failureException("Something is messed up before this assertion. Now here is a bunch of info to help with debugging. This is really quite a lot of info you know. Yes it is very long isnt it?")
谢谢!
【问题讨论】:
标签: python formatting assertions nosetests python-unittest