【发布时间】:2014-02-02 17:27:01
【问题描述】:
我正在从 PyUnit 迁移到 Pytest,我发现,与 PyUnit 不同,Pytest 在运行测试(打印点)时不会在快速报告中区分测试报告中的失败和错误。如何教 Pytest 做呢?
更新
似乎它仅对使用 Pytest 执行的 PyUnit 测试有效,感谢flub 提供线索。
代码:
import unittest
class TestErrorFail(unittest.TestCase):
def test_error(self):
raise Exception('oops')
def test_fail(self):
self.assertTrue(False)
输出:
================================ test session starts =================================
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2
plugins: django
collected 2 items
sometests.py FF
====================================== FAILURES ======================================
______________________________ TestErrorFail.test_error ______________________________
self = <sometests.TestErrorFail testMethod=test_error>
def test_error(self):
> raise Exception('oops')
E Exception: oops
sometests.py:5: Exception
______________________________ TestErrorFail.test_fail _______________________________
self = <sometests.TestErrorFail testMethod=test_fail>
def test_fail(self):
> self.assertTrue(False)
E AssertionError: False is not true
sometests.py:8: AssertionError
============================== 2 failed in 0.69 seconds ==============================
【问题讨论】:
标签: python testing pytest python-unittest