【发布时间】:2014-06-04 04:46:41
【问题描述】:
【问题讨论】:
标签: django django-tests
【问题讨论】:
标签: django django-tests
from unittest import TestCase
class MyTest(TestCase):
def test1(self):
print 'before'
self.assertEquals(2+2, 5)
print 'after'
python -i debugunit.py
要以交互方式运行测试,请创建一个TestCase 实例,并为其提供测试名称作为参数。要运行它,请调用生成的对象。
>>> print MyTest('test1')()
before
None
“2+2!=5”异常被单元测试机器消耗。要运行该集合(使用setUp 和tearDown 等),请运行debug() 方法:
>>> MyTest('test1').debug()
before
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/unittest/case.py", line 400, in debug
getattr(self, self._testMethodName)()
File "debugunit.py", line 6, in test1
self.assertEquals(2+2, 5)
File "/usr/lib/python2.7/unittest/case.py", line 515, in assertEqual
assertion_func(first, second, msg=msg)
File "/usr/lib/python2.7/unittest/case.py", line 508, in _baseAssertEqual
raise self.failureException(msg)
AssertionError: 4 != 5
【讨论】:
pdb。我只是好奇TestCase.Debug() 是否提供了更好的东西。你能解释一下如何手动启动测试吗?
debug() 替换了答案——希望这会有所帮助!