【发布时间】:2014-06-13 18:51:50
【问题描述】:
代码:
# coding=utf-8
import pytest
def whatever():
return 9/0
def test_whatever():
try:
whatever()
except ZeroDivisionError as exc:
pytest.fail(exc, pytrace=True)
输出:
================================ test session starts =================================
platform linux2 -- Python 2.7.3 -- py-1.4.20 -- pytest-2.5.2
plugins: django, cov
collected 1 items
pytest_test.py F
====================================== FAILURES ======================================
___________________________________ test_whatever ____________________________________
def test_whatever():
try:
whatever()
except ZeroDivisionError as exc:
> pytest.fail(exc, pytrace=True)
E Failed: integer division or modulo by zero
pytest_test.py:12: Failed
============================== 1 failed in 1.16 seconds ==============================
如何使 pytest 打印回溯,以便我查看whatever 函数中的哪个位置引发了异常?
【问题讨论】:
-
我得到了整个回溯,Ubuntu 14.04,Python 2.7.6
-
@thefourtheye 请提供输出要点。我尝试使用 Python 2.7.4 和 Ubuntu 14.04 - 结果与我在主帖中描述的相同。
-
@GillBates 一会儿我读到“比尔盖茨”..
标签: python unit-testing testing pytest