我找不到一种方法来向表示测试步骤的HTML报告中添加字符串。
我在https://pypi.org/project/pytest-html/中看到,我应该尝试一下:
extra.text('Add some simple Text')但它似乎不起作用。
from pytest_html import extras
class 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我希望每个测试都包含以字符串形式表示的带有信息描述的测试步骤。
有没有办法做到这一点?
发布于 2019-01-01 22:44:02
在这种情况下,我建议您尝试使用allure而不是pytest-html。它很容易与pytest集成,并且api使用起来非常舒适。
有关更多信息,请查看this repository。
这个是给usage examples的。
发布于 2019-01-03 08:40:17
诱惑当然更适合您的需求,因为它具有所有的测试报告功能(步骤、功能、故事等)。为了pytest。但是它是用java编写的,你需要在本地安装pytest的诱惑力和诱导性的二进制文件才能工作。而且你可能不得不跳过几个圈子才能让它在你现有的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我没有在本地运行代码,但这是添加步骤的最终代码应该是什么样子。
https://stackoverflow.com/questions/53915285
复制相似问题