24-pytest-allure命令行参数

本文介绍如何使用Allure命令行工具生成并查看自动化测试报告,包括generate、serve及open命令的具体用法,并提供了两种打开报告的方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

查看帮助文档

generate 命令行参数

open 命令行参数

serve 命令行参数

打开报告两种方式


查看帮助文档

  • allure  --help
  • 格式:allure [options] [command] [command options]
Usage: allure [options] [command] [command options]
  Options:
    --help
      Print commandline help.   帮助文档
    -q, --quiet   
      Switch on the quiet mode.   安静模式
      Default: false
    -v, --verbose            
      Switch on the verbose mode.    冗长模式
      Default: false
    --version
      Print commandline version.    版本
      Default: false
  Commands:
    generate      Generate the report
      Usage: generate [options] The directories with allure results
        Options:
          -c, --clean
            Clean Allure report directory before generating a new one.   删除allure报告生成的目录
            Default: false
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.
          -o, --report-dir, --output    allure报告目录
            The directory to generate Allure report into.
            Default: allure-report

    serve      Serve the report
      Usage: serve [options] The directories with allure results
        Options:
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0
          --profile
            Allure commandline configuration profile.

    open      Open generated report
      Usage: open [options] The report directory
        Options:
          -h, --host
            This host will be used to start web server for the report.
          -p, --port
            This port will be used to start web server for the report.
            Default: 0

    plugin      Generate the report
      Usage: plugin [options]
        Options:
          --config
            Allure commandline config path. If specified overrides values from
            --profile and --configDirectory.
          --configDirectory
            Allure commandline configurations directory. By default uses
            ALLURE_HOME directory.
          --profile
            Allure commandline configuration profile.

generate 命令行参数

  • 作用:生成 allure 的html 报告
  • 格式:generate [options] allure报告目录

    命令行选项

  • -c, --clean : 删除allure之前生成的报告目录
  • -o, --report-dir, --output :生成allure报告目录,默认为allure-report

open 命令行参数

  • 作用:打开生成的 allure 报告,就是打开 generate 命令生成的报告
  • 格式:open [options] allure报告目录

   命令行选项

  • -h, --host : 启动报告的web服务器IP
  • -p, --port : 启动报告的web服务器端口

serve 命令行参数

  • 作用:启动 allure 服务,打开 allure 报告
  • 格式:serve [options]  allure报告目录

打开报告两种方式

  • 方式1:allure serve 报告目录
# -*- coding: utf-8 -*-
# @Time    : 2021/12/18
# @Author  : 大海

import os


def test_1():
    print('这是case1')


def test_2():
    print('这是case2')


if __name__ == '__main__':
    # 运行pytest,--alluredir 指定报告结果目录为 allure-report
    os.system('pytest -sq test_43.py --alluredir=./allure-report')
    # 打开allure报告 (目录与上面生成结果目录需一致)
    os.system('allure serve ./allure-report')
  • 方式2:allure generate + allure open 报告目录
# -*- coding: utf-8 -*-
# @Time    : 2021/12/18
# @Author  : 大海

import os
import time


def test_1():
    print('这是case1')


def test_2():
    print('这是case2')


if __name__ == '__main__':
    # 运行pytest,--alluredir 指定报告结果目录为 allure
    os.system('pytest -sq test_44.py --alluredir=./allure')
    # 生成HTML报告  -c 删除上次报告   -o 指定HTML报告路径   ./allure 是用户生成HTML报告的文件信息,是上一步骤生成的
    os.system('allure generate -c -o ./allure-report ./allure')
    # 打开allure报告 (目录与上面生成HTML报告目录一致)
    os.system('allure open ./allure-report')

<think>好的,我现在要帮助用户解决如何下载并安装allure-pytest工具的问题。首先,我需要回顾用户提供的引用内容,确保给出的步骤准确无误。 根据引用[2],用户提到了使用pip安装allure-pytest命令,包括使用豆瓣镜像加速下载。同时,引用[3]和[4]指出还需要下载Allure命令行工具并配置环境变量。因此,安装过程应该分为两个主要部分:安装allure-pytest插件和配置Allure命令行工具。 首先,安装allure-pytest插件。用户可能已经安装了pytest,但需要确认。如果未安装,应该先安装pytest。然后通过pip安装allure-pytest,这里推荐使用镜像源加快速度,比如豆瓣源。命令应该是: pip install allure-pytest -i http://pypi.douban.com/simple/ 接下来是Allure命令行工具的安装。用户需要前往GitHub的发布页面下载合适的版本,解压后配置环境变量。引用[3]提到解压后要将bin目录添加到系统Path变量中。对于不同操作系统,步骤可能略有不同,需要分别说明Windows和Mac/Linux的方法。 另外,引用[4]提到需要配置Java环境,因为Allure依赖Java 8+。这一点可能用户没有提到,但根据引用内容,必须包含进去。因此,需要检查Java是否安装,如果没有,指导用户安装JDK。 最后,验证安装是否成功,可以通过运行allure --version和pytest --version来确认。同时,生成测试报告的基本步骤也需要简要说明,让用户知道如何使用allure-pytest。 需要注意用户可能遇到的常见问题,比如镜像源不可用、环境变量配置错误、Java未安装等,应该在步骤中给出提示或解决方法。例如,如果安装过程中出现权限问题,可能需要使用管理员权限运行命令提示符。 总结步骤: 1. 安装pytest(如有需要) 2. 使用pip安装allure-pytest 3. 下载Allure命令行工具并配置环境变量 4. 安装Java环境 5. 验证安装 需要确保每个步骤清晰,命令正确,并且覆盖不同操作系统的差异。同时,引用正确的来源,比如引用[2]、[3]、[4]中的信息,确保用户能顺利按照指导完成安装。</think>以下是如何下载并安装$allure-pytest$工具的详细步骤: ### 一、安装allure-pytest插件 1. **安装pytest**(若未安装): ```bash pip install pytest -i http://pypi.douban.com/simple/ ``` 2. **安装allure-pytest插件**: ```bash pip install allure-pytest -i http://pypi.douban.com/simple/ ``` 此命令通过豆瓣镜像加速下载[^2] ### 二、安装Allure命令行工具 1. **下载Allure**: - 访问GitHub Releases页面:https://github.com/allure-framework/allure2/releases [^3] - 根据操作系统选择对应版本(如Windows选.zip,Mac/Linux选.tgz) 2. **解压并配置环境变量**: - **Windows**: - 解压到目录(如$C:\allure$) - 添加系统变量:将$C:\allure\bin$添加到Path变量 - **Mac/Linux**: ```bash sudo tar -zxvf allure-*.tgz -C /usr/local/ echo 'export PATH=$PATH:/usr/local/allure/bin' >> ~/.bashrc source ~/.bashrc ``` ### 三、验证Java环境 Allure依赖Java 8+运行环境[^4],需执行: ```bash java -version ``` 若未安装,需先下载JDK:https://www.oracle.com/java/technologies/downloads/ ### 四、验证安装 1. 检查Allure版本: ```bash allure --version ``` 2. 检查插件状态: ```bash pytest --version # 输出应包含allure-pytest ``` ### 五、生成测试报告 1. 运行测试时添加参数: ```bash pytest --alluredir=./report ``` 2. 生成可视化报告: ```bash allure serve ./report ``` §§常见问题§§ 1. **安装时报SSL错误**:尝试添加$\texttt{--trusted-host}$参数 ```bash pip install allure-pytest -i http://pypi.douban.com/simple --trusted-host pypi.douban.com ``` 2. **allure命令未找到**:检查环境变量是否配置正确 3. **报告无法生成**:确认Java环境已安装且版本≥8 [^1]: 安装allure-pytest报错示例 : 使用镜像源安装allure-pytest : Allure命令行工具下载地址 [^4]: Java环境依赖要求
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱学习de测试小白

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值