首先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>TestScriptsname>
<labels/>
<test-cases>
<test-case start="1544418468984" status="passed" stop="1544418468987">
<name>test_asserts.test_addname>
<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_addname>
<title>test_addtitle>
<attachments/>
<steps/>
step>
steps>
test-case>
<test-case start="1544418468990" status="passed" stop="1544418468991">
<name>test_asserts.test_add2name>
<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_add2name>
<title>test_add2title>
<attachments/>
<steps/>
step>
steps>
test-case>
<test-case start="1544418468992" status="passed" stop="1544418468993">
<name>test_asserts.test_add3name>
<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_add3name>
<title>test_add3title>
<attachments/>
<steps/>
step>
steps>
test-case>
<test-case start="1544418468994" status="failed" stop="1544418469045">
<name>test_asserts.test_add4name>
<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: AssertionErrorstack-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_inname>
<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_inname>
<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_truename>
<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: AssertionErrorstack-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_4name>
<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_3name>
<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_6name>
<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_2name>
<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 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()