首页 > 其他 > 详细

pytest那些事01_执行结果内容改造

时间:2020-07-13 18:21:03      阅读:56      评论:0      收藏:0      [点我收藏+]

前言

改造pytest命令行执行测试用例时,返回的内容。

添加用例描述

在编写测试用例时,若将测试目的写为测试用例名称,可能会导致用例名称过长,但是使用简短的编号表示用例名称时,从执行结果中又无法知晓具体的测试逻辑,基于此,想要改造测试结果的返回内容,携带上用例描述信息。
在conftest.py中添加代码如下:

@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.description = str(item.function.__doc__)
    if not report.description:
        report.nodeid = report.nodeid.encode("utf-8").decode("unicode_escape")
    else:
        report.nodeid = "Description of this test is : " + report.description

效果如下:

test_doc.py::TestDoc::test_01
Description of this test is : this is the first test PASSED                                                                      [ 33%]
test_doc.py::TestDoc::test_02
Description of this test is : this is the second test PASSED                                                                     [ 66%]
test_doc.py::TestDoc::test_03
Description of this test is : None PASSED                                                                                        [100%]

如果有更好的解决方法,欢迎留言

pytest那些事01_执行结果内容改造

原文:https://www.cnblogs.com/SodaAir/p/12564944.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!