预期失败被计算为错误而不是通过
我正在使用 expectedFailure
这个功能,因为我遇到了一个我现在无法修复的bug,但我想在将来再来处理它。我理解 expectedFailure
的意思是,这个测试会被算作通过,但在总结中会显示有多少个预期的失败(这和跳过的测试类似)。
但是,当我运行我的测试套件时,我得到了以下结果:
$ ./manage.py test eav.QueryTest
Creating test database for alias 'default'...
.EE
======================================================================
ERROR: test_q_object_with_exclude (eav.tests.managers.QueryTest)
----------------------------------------------------------------------
_ExpectedFailure
======================================================================
ERROR: test_q_objects_unioned (eav.tests.managers.QueryTest)
----------------------------------------------------------------------
_ExpectedFailure
----------------------------------------------------------------------
Ran 3 tests in 1.095s
FAILED (errors=2)
Destroying test database for alias 'default'...
我不确定这是Django的测试运行器的问题,还是我自己做错了什么。
@unittest.expectedFailure
def test_q_object_with_exclude(self):
# Everyone except Bob
q_set = eav_m.Process.objects.exclude(
Q(eav__details__city__contains='Y'))
self.assertEqual(q_set.count(), 4)
2 个回答
0
你应该看看这个StackOverflow上的问题,因为这不是正常的情况。使用了expectedFailure
装饰器的测试,如果测试失败了,不应该被算作失败。
8
你对 expectedFailure
的理解是正确的。你的问题在于那些测试并没有失败,而是抛出了一个异常,这和失败是不一样的。
你需要的装饰器是 skip
。