【发布时间】:2019-01-03 08:40:17
【问题描述】:
我找不到将字符串添加到代表我的测试步骤的 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
我希望每个测试都包含以字符串表示的测试步骤,并带有信息性描述。
有什么办法吗?
【问题讨论】:
-
extras.text()不会在报告中添加任何内容,只会准备要添加的文本。您需要在pytest_runtest_makereport钩子的自定义impl中使用report.extra.append(),如文档中的示例所示。 -
谢谢,它成功了。我还有一个问题,如何将 costum 消息从测试方法传递给 pytest_runtest_makereport 钩子?
-
我可能会使用会话对象,例如
def test_spam(request): request.session.foo = 'bar'和def pytest_runtest_makereport(item, call): foo = item.session.foo
标签: python pytest pytest-html