亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 pytest-html 將測試步驟寫入生成的 html 報告?

如何使用 pytest-html 將測試步驟寫入生成的 html 報告?

忽然笑 2021-09-24 15:11:40
我找不到將字符串添加到代表我的測試步驟的 HTML 報告的方法。我在https://pypi.org/project/pytest-html/ 看到我應該嘗試:extra.text('Add some simple Text')但似乎它不起作用。from pytest_html import extrasclass FirstFeatureTests:    def setup_class(self):        print("\n------------ in setup_class ------------")    def teardown_class(self):        print("------------ in teardown_class ------------")    @mark.example    def test_1_first_feature(self):        print("starting test !!!!!")        extras.text("step 1: ")        extras.text('step 2: ')        assert True我希望每個測試都包含表示為帶有信息描述的字符串的測試步驟。有什么辦法嗎?
查看完整描述

2 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

Allure 當然更適合您的需求,因為它具有 pytest 的所有測試報告功能(步驟、功能、故事等)。但它是用 java 編寫的,您需要在本地安裝 pytest allure 以及 allure 二進制文件才能使其工作。而且您可能需要跳幾下才能使其在您現有的 pytest 代碼庫中工作。


如果您想使用 pytest-html 生成測試步驟,這是一個可能的解決方案:


# Contents of top level conftest.py

import pytest


@pytest.fixture(scope='session', autouse=True)

def step(request):

    @pytest.mark.optionalhook

    def pytest_html_results_table_html(request, report, data):

        data.append(html.div(str(request.param), class_='Step'))


#Contents of fixture or test code

def test_a(step):

    step("abc")

    assert True

我沒有在本地運行代碼,但這就是添加步驟的最終代碼應該是什么樣子。


查看完整回答
反對 回復 2021-09-24
?
寶慕林4294392

TA貢獻2021條經驗 獲得超8個贊

在這種情況下,我建議您嘗試allure而不是 pytest-html 。它很容易與 pytest 集成,而且 api 使用起來非常舒服。

查看此存儲庫以獲取更多信息。

這一個是使用示例。


查看完整回答
反對 回復 2021-09-24
  • 2 回答
  • 0 關注
  • 462 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號