首先python环境中安装pytest和pytest_allure_adaptor模块,命令如下
环境配置
pip install pytest pip install pytest_allure_adaptor
执行测试
pytest -s -q --alluredir [path_to_report_dir]
<ns0:test-suite xmlns:ns0="urn:model.allure.qatools.yandex.ru" start="1544418468984" stop="1544418469065"> <name>TestScripts</name> <labels/> <test-cases> <test-case start="1544418468984" status="passed" stop="1544418468987"> <name>test_asserts.test_add</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps> <step start="1544418468987" status="passed" stop="1544418468987"> <name>test_add</name> <title>test_add</title> <attachments/> <steps/> </step> </steps> </test-case> <test-case start="1544418468990" status="passed" stop="1544418468991"> <name>test_asserts.test_add2</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps> <step start="1544418468991" status="passed" stop="1544418468991"> <name>test_add2</name> <title>test_add2</title> <attachments/> <steps/> </step> </steps> </test-case> <test-case start="1544418468992" status="passed" stop="1544418468993"> <name>test_asserts.test_add3</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps> <step start="1544418468993" status="passed" stop="1544418468993"> <name>test_add3</name> <title>test_add3</title> <attachments/> <steps/> </step> </steps> </test-case> <test-case start="1544418468994" status="failed" stop="1544418469045"> <name>test_asserts.test_add4</name> <failure> <message>AssertionError: assert 39 >= 50 + where 39 = add(17, 22)</message> <stack-trace>def test_add4(): > assert add(17,22) >= 50 E assert 39 >= 50 E + where 39 = add(17, 22) test_asserts.py:34: AssertionError</stack-trace> </failure> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps/> </test-case> <test-case start="1544418469046" status="passed" stop="1544418469047"> <name>test_asserts.test_in</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps/> </test-case> <test-case start="1544418469048" status="passed" stop="1544418469049"> <name>test_asserts.test_not_in</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps/> </test-case> <test-case start="1544418469050" status="failed" stop="1544418469054"> <name>test_asserts.test_true</name> <failure> <message>AssertionError: assert not True + where True = is_prime(7)</message> <stack-trace>def test_true(): > assert not is_prime(7) E assert not True E + where True = is_prime(7) test_asserts.py:65: AssertionError</stack-trace> </failure> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps/> </test-case> <test-case start="1544418469055" status="passed" stop="1544418469057"> <name>test_fixture1.test_numbers_3_4</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps/> </test-case> <test-case start="1544418469058" status="passed" stop="1544418469059"> <name>test_fixture1.test_strings_a_3</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps/> </test-case> <test-case start="1544418469060" status="passed" stop="1544418469062"> <name>test_fixture2.TestUM.test_numbers_5_6</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps/> </test-case> <test-case start="1544418469064" status="passed" stop="1544418469065"> <name>test_fixture2.TestUM.test_strings_b_2</name> <attachments/> <labels> <label name="severity" value="normal"/> <label name="thread" value="9944-MainThread"/> <label name="host" value="DESKTOP-BE70S9D"/> <label name="framework" value="pytest"/> <label name="language" value="cpython3"/> </labels> <steps/> </test-case> </test-cases> </ns0:test-suite>
使用allure-commandline将xml制作成html报告
执行命令:allure generate directory-with-results/ -o directory-with-report
查看报告
报告样式
生成报告方法封装
import os from time import sleep class GenerateAllureReport: def __init__(self, case_path, xml_path, report_path): self.case_path = case_path self.xml_path = xml_path self.report_path = report_path def run(self): generate_xml = "pytest " + self.case_path + " -s -q --alluredir " + self.xml_path os.system(generate_xml) sleep(10) generate_report = "allure generate " + self.xml_path + " -o " + self.report_path + " --clean" os.system(generate_report) sleep(10) if __name__ == '__main__': GenerateAllureReport("D://PythonPrograms/Python_Pytest/TestScripts", "D://PythonPrograms/Python_Pytest//TestResult", "D://PythonPrograms/Python_Pytest//TestResult//Report").run()
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算