我找不到將字符串添加到代表我的測試步驟的 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
我沒有在本地運行代碼,但這就是添加步驟的最終代碼應該是什么樣子。

寶慕林4294392
TA貢獻2021條經驗 獲得超8個贊
添加回答
舉報
0/150
提交
取消