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

編寫case
# -*- coding: utf-8 -*-
import os
import shutil
def test_1():
print('這是case1')
def test_2():
print('這是case2')
if __name__ == '__main__':
# 運行pytest,--alluredir 指定報告結(jié)果目錄為 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報告 (目錄與上面生成結(jié)果目錄需一致)
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.dhdzp.com/</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 指定報告結(jié)果目錄為 allure-report
os.system('pytest -sq test_69.py --alluredir=./allure-report --clean-alluredir')
shutil.copy('./environment.xml', './allure-report/environment.xml')
# 打開allure報告 (目錄與上面生成結(jié)果目錄需一致)
os.system('allure serve ./allure-report')查看報告

到此這篇關(guān)于pytest allure添加環(huán)境信息實例講解的文章就介紹到這了,更多相關(guān)pytest allure環(huán)境信息內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在Windows中安裝Spire.XLS?for?Python的操作指南
Spire.XLS?for?Python?是一款專業(yè)的?Python?Excel?庫,可用于在各種?Python?應(yīng)用程序中讀取、創(chuàng)建、編輯和轉(zhuǎn)換?Excel?(.xls?&?.xlsx)?文件,本文將介紹如何在?Windows?中安裝?Spire.XLS?for?Python,需要的朋友可以參考下2025-02-02
如何使用python3獲取當(dāng)前路徑及os.path.dirname的使用
這篇文章主要介紹了如何使用python3獲取當(dāng)前路徑及os.path.dirname的使用,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2019-12-12
Python?內(nèi)置函數(shù)sorted()的用法
這篇文章主要介紹了Python?內(nèi)置函數(shù)sorted()的用法,文章內(nèi)容介紹詳細具有一的參考價值,需要的小伙伴可以參考一下,希望對你的學(xué)習(xí)有所幫助2022-03-03
python實戰(zhàn)之Scrapy框架爬蟲爬取微博熱搜
前面講解了Scrapy中各個模塊基本使用方法以及代理池、Cookies池。接下來我們以一個反爬比較強的網(wǎng)站新浪微博為例,來實現(xiàn)一下Scrapy的大規(guī)模爬取。2021-09-09

