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")
没伞的孩子,就要学会在雨中奔跑!
原文地址:https://www.cnblogs.com/mikigo/p/14263374.html