pytest allure添加環(huán)境信息實例講解
前言
本篇來學習下在allure中如何添加環(huán)境信息
properties文件
在allure的report根目錄下添加一個 environment.properties 文件,allure報告就會顯示在報告中
Author=DH
NativePlace=Liaoning
City=Beijing
Age=28
Professional=Test Engineer
Blog=http://www.dbjr.com.cn/

編寫case
# -*- coding: utf-8 -*-
import os
import shutil
def test_1():
print('這是case1')
def test_2():
print('這是case2')
if __name__ == '__main__':
# 運行pytest,--alluredir 指定報告結果目錄為 allure-report
os.system('pytest -sq test_69.py --alluredir=./allure-report --clean-alluredir')
# 這里是在項目根路徑下創(chuàng)建的environment.properties文件拷貝到allure-report報告中,保證環(huán)境文件不會被清空
shutil.copy('./environment.properties', './allure-report/environment.properties')
# 打開allure報告 (目錄與上面生成結果目錄需一致)
os.system('allure serve ./allure-report')運行case,查看報告

xml文件
- 在allure的report根目錄下添加一個 environment.xml文件,allure報告就會顯示在報告中
- environment.xml
<environment>
<parameter>
<key>Author</key>
<value>DH</value>
</parameter>
<parameter>
<key>NativePlace</key>
<value>Liaoning</value>
</parameter>
<parameter>
<key>City</key>
<value>Production</value>
</parameter>
<parameter>
<key>Age</key>
<value>28</value>
</parameter>
<parameter>
<key>Professional</key>
<value>Test Engineer</value>
</parameter>
<parameter>
<key>Blog</key>
<value>http://www.dbjr.com.cn/</value>
</parameter>
</environment>
編寫case
# -*- coding: utf-8 -*-
import os
import shutil
def test_1():
print('這是case1')
def test_2():
print('這是case2')
if __name__ == '__main__':
# 運行pytest,--alluredir 指定報告結果目錄為 allure-report
os.system('pytest -sq test_69.py --alluredir=./allure-report --clean-alluredir')
shutil.copy('./environment.xml', './allure-report/environment.xml')
# 打開allure報告 (目錄與上面生成結果目錄需一致)
os.system('allure serve ./allure-report')查看報告

到此這篇關于pytest allure添加環(huán)境信息實例講解的文章就介紹到這了,更多相關pytest allure環(huán)境信息內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
python通用數(shù)據(jù)庫操作工具 pydbclib的使用簡介
這篇文章主要介紹了python通用數(shù)據(jù)庫操作工具 pydbclib的使用簡介,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2020-12-12
Python實現(xiàn)灰色關聯(lián)分析與結果可視化的詳細代碼
今天小編通過代碼以灰色色系為例給大家介紹Python灰色關聯(lián)分析實現(xiàn)方法,灰色關聯(lián)度分析對于一個系統(tǒng)發(fā)展變化態(tài)勢提供了量化的度量,非常適合動態(tài)歷程分析,感興趣的朋友一起看看吧2022-03-03

