標簽:百度搜索 print work 找不到 pytho 右擊 inf style 信息
簡介:Allure非常適合作爲自動化測試報告,這裏總結下Pytest使用的Allure測試報告的用法
環境准備
所需環境
ide使用PyCharm
python 3.7
pytest 5.3.2
allure-pytest 2.8.13
allure-pytest 安装
在已经安装python3和pytest的前提下,打开PyCharm,进入Project Interpreter,點擊“+”,添加allure-pytest包
搜索allure,选中allure-pytest,點擊“Install Package"
allure命令行工具安裝
這個工具主要用來把測試用例的運行結果轉換成html格式
去GitHub上下載:https://github.com/allure-framework/allure2/releases
下載完成後解壓到本地,並把bin目錄添加到環境變量
设置环境变量,右擊電腦,選擇【屬性】,點擊【高級系統設置】,點擊【環境變量】,選擇系統變量,找到path变量,點擊【編輯】,點擊【新建】,輸入\安裝路徑\allure\bin(注意:这里的路径一定要包括 \bin ),點擊【確定】
檢測環境變量是否正確配置,按住鍵盤【win】+【R】,對話框中輸入cmd,回车进入命令行,輸入allure,如果出现以下信息,则配置成功
代碼演示
代碼如下,test_allure_demo.py
# encoding: utf-8 """ @File : test_allure_demo.py @Author : 灵枢 @Time : 2020/4/13 5:05 PM @Desc : """ import allure @allure.step("步驟1:打開百度") def step_1(): print("111") @allure.step("步驟2:輸入關鍵字") def step_2(): print("222") @allure.feature("搜索") class TestEditPage(): @allure.story("百度搜索") def test_1(self): ‘‘‘這是測試百度搜索‘‘‘ step_1() step_2() print("百度一下,你就知道") @allure.story("谷歌搜索") def test_2(self): ‘‘‘這是測試谷歌搜索‘‘‘ assert 1 == 2, "搜索失敗"
在PyCharm的Terminal窗口運行:
先切換到測試代碼的目錄下,然後執行命令:
pytest test_allure_demo.py --alluredir=output
terminal終端輸入allure serve 报告目录(注意:pycharm有時候找不到系統的變量,以管理員身份運行Pycharm可以解決)或者cmd命令,在項目目錄下輸入allure serve 报告目录,生成html可視化報告。注意:報告生成後,自动调用默认浏览器显示报告 ,有可能會調用IE浏覽器,無法顯示,將地址複制後在谷歌中打開即可。
執行後,會自動打開浏覽器的一個頁面來顯示測試報告,如下圖
查看報告
標簽:百度搜索 print work 找不到 pytho 右擊 inf style 信息
原文地址:https://www.cnblogs.com/liangcr/p/15014945.html