繁体   English   中英

pytest 报告摘要显示错误信息

[英]Pytest report summary to display error information

我对 pytest 钩子和插件比较陌生,我无法弄清楚如何让我的 pytest 代码为我提供失败原因的测试执行摘要。

考虑代码:

class Foo:
    def __init__(self, val):
        self.val = val

    def test_compare12():
        f1 = Foo(1)
        f2 = Foo(2)
        assert f1 == f2, "F2 does not match F1"

    def test_compare34():
        f3 = Foo(3)
        f4 = Foo(4)
        assert f3 == f4, "F4 does not match F3"

当我使用 -v 选项运行 pytest 脚本时,它在控制台上给我以下结果:

========================= test session starts=================================
platform darwin -- Python 2.7.5 -- py-1.4.26 -- pytest-2.7.0 --    /Users/nehau/src/QA/bin/python
rootdir: /Users/nehau/src/QA/test, inifile: 
plugins: capturelog
collected 2 items 

test_foocompare.py::test_compare12 FAILED
test_foocompare.py::test_compare34 FAILED

================================ FAILURES ===============================
_______________________________ test_compare12 _________________________

def test_compare12():
    f1 = Foo(1)
    f2 = Foo(2)
>       assert f1 == f2, "F2 does not match F1"
E       AssertionError: F2 does not match F1
E       assert <test.test_foocompare.Foo instance at 0x107640368> == <test.test_foocompare.Foo instance at 0x107640488>

test_foocompare.py:11: AssertionError
_____________________________ test_compare34______________________________

def test_compare34():
    f3 = Foo(3)
    f4 = Foo(4)
>       assert f3 == f4, "F4 does not match F3"
E       AssertionError: F4 does not match F3
E       assert <test.test_foocompare.Foo instance at 0x107640248> == <test.test_foocompare.Foo instance at 0x10761fe60>

test_foocompare.py:16: AssertionError

=============================== 2 failed in 0.01 seconds ==========================

我正在运行接近 2000 个测试用例,因此如果我可以使用以下格式的 pytest 显示输出,那将非常有帮助:

::
test_foocompare.py::test_compare12 FAILED AssertionError:F2 does not match F1
test_foocompare.py::test_compare34 FAILED AssertionError:F2 does not match F1
::

我看过 pytest_runtest_makereport 插件,但似乎无法让它工作。 有人有其他想法吗?

谢谢

试试 -tb 标志:

pytest --tb=line

这为每个测试提供一行输出。 请参阅文档

还可以尝试pytest -v --tb=no显示所有通过/失败结果。

尝试-rA选项pytest 它将在日志末尾提供一个摘要,显示所有(失败、跳过等和通过)。

请参阅https://docs.pytest.org/en/latest/usage.html#detailed-summary-report

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM