首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有办法在每个测试的pytest-html报告中显示测试作者的名字?

有没有办法在每个测试的pytest-html报告中显示测试作者的名字?
EN

Stack Overflow用户
提问于 2022-01-10 10:58:59
回答 1查看 259关注 0票数 -1

有没有办法在每个测试的pytest-html报告中显示测试作者的名字?

EN

回答 1

Stack Overflow用户

发布于 2022-01-11 09:49:58

是。你可以做到的。在每个测试模块中添加__author__属性。

代码语言:javascript
复制
# test_add.py

__author__ = 'Vivek R'


def add(x, y):
    return x + y


def test_add():
    assert add(5, 4) == 9

并在conftest.py文件中调用一些固定装置。

代码语言:javascript
复制
# conftest.py

from py.xml import html
import pytest


def pytest_html_results_table_header(cells):
    cells.append(html.th("Author"))


def pytest_html_results_table_row(report, cells):
    cells.append(html.td(report.author))


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    report.author = item.module.__author__

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70651334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档