UOS(国产Linux操作系统)下使用pytest生成allure自动化测试报告

  1. 测试环境:uos

  2. 安装 Java 环境:

    sudo apt-get install -y openjdk-8-jdk
    

    java -version 查看 java 版本

  3. 安装 pytest

    sudo pip3 install pytest
    
  4. 安装 allure-pytest

    sudo pip3 install allure-pytest
    
  5. 安装 allure

    git 地址:https://github.com/allure-framework/allure2

    uos 系统可以直接采用命令安装

    sudo apt-get install allure
    
  6. 配置 allure 环境变量

    ln -s allure-2.13.8/bin/allure /usr/bin/allure
    

    查看 allure 的权限,建议 chmod 赋权

  7. 使用 pytest 执行测试用例

    pytest test_001.py --alluredir=/tmp/my_allure_results --clean-alluredir
    
  8. 生成在线 html 报告

    allure serve /tmp/my_allure_results
    
  9. 使用 generate 命令导出 HTML 报告到新的目录

    allure generate allure-results -o allure-report
    
    • -c 在生成报告之前先清理之前的报告目录
    • -o 指定生成报告的文件夹
  10. 使用 open 命令在浏览器中打开 HTML 报告

    allure open allure-report
    

11. 使用 py 文件批量执行

import os,sys
sys.path.append(os.path.abspath('..'))
from setting.config import *

def pytest_run(git_branch, pattern):
os.system(
'pytest {}/cases_{} -k"{}" '
'--alluredir=/tmp/allure_results'
'--clean-alluredir'.format(CASES_PATH, git_branch, pattern))
os.system('allure serve /tmp/allure_results/')

if name == 'main':
pytest_run("1040", "music")