如果你还想从头学起Pytest,可以看看这个系列的文章哦!
https://www.cnblogs.com/poloyy/category/1690628.html
allure除了支持pytest自带的特性之外(fixture、parametrize、xfail、skip),自己本身也有强大的特性可以在pytest中使用
@allure.step()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ =
__Time__ = 2020-04-08 21:24
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
"""
import allure
@allure.step("第一步")
def passing_step():
pass
@allure.step("第二步")
def step_with_nested_steps():
nested_step()
@allure.step("第三步")
def nested_step():
nested_step_with_arguments(1, 'abc')
@allure.step("第四步{0},{arg2}")
def nested_step_with_arguments(arg1, arg2):
pass
@allure.step("第五步")
def test_with_nested_steps():
passing_step()
step_with_nested_steps()
step()
step()
作用:allure报告还支持显示许多不同类型的附件,可以补充测试结果;自己想输出啥就输出啥,挺好的
语法: allure.attach(body, name, attachment_type, extension)
allure.attachment_type
source:文件路径,相当于传一个文件
其他参数和上面的一致
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ =
__Time__ = 2020-04-08 21:24
__Author__ = 小菠萝测试笔记
__Blog__ = https://www.cnblogs.com/poloyy/
"""
import allure
import pytest
@pytest.fixture
def attach_file_in_module_scope_fixture_with_finalizer(request):
allure.attach('在fixture前置操作里面添加一个附件txt', 'fixture前置附件', allure.attachment_type.TEXT)
def finalizer_module_scope_fixture():
allure.attach('在fixture后置操作里面添加一个附件txt', 'fixture后置附件',
allure.attachment_type.TEXT)
request.addfinalizer(finalizer_module_scope_fixture)
def test_with_attacments_in_fixture_and_finalizer(attach_file_in_module_scope_fixture_with_finalizer):
pass
def test_multiple_attachments():
allure.attach('<head></head><body> 一个HTML页面 </body>', 'Attach with HTML type', allure.attachment_type.HTML)
allure.attach.file('./reports.html', attachment_type=allure.attachment_type.HTML)
这是一个txt附件
这是一个用了 allure.attach() 来插入一段自己写的HTML和 allure.attach.file() 来导入一个已存在的HTML文件(pytest-html报告)