若是你還想從頭學起Pytest,能夠看看這個系列的文章哦!html
https://www.cnblogs.com/poloyy/category/1690628.htmlpython
allure除了支持pytest自帶的特性以外(fixture、parametrize、xfail、skip),本身自己也有強大的特性能夠在pytest中使用函數
#!/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()
做用:allure報告還支持顯示許多不一樣類型的附件,能夠補充測試結果;本身想輸出啥就輸出啥,挺好的測試
語法: allure.attach(body, name, attachment_type, extension) spa
source:文件路徑,至關於傳一個文件code
其餘參數和上面的一致htm
#!/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附件blog
這是一個用了 allure.attach() 來插入一段本身寫的HTML和 allure.attach.file() 來導入一個已存在的HTML文件(pytest-html報告)ip