pytest-allure
时间: 2025-01-24 19:03:28 浏览: 71
### 配置与使用 Allure 生成 PyTest 测试报告
#### pytest.ini 文件配置
为了更好地管理和控制测试用例的执行,可以在 `pytest.ini` 中定义特定选项。此文件位于项目的根目录下,允许自定义多个参数以适应不同的需求[^1]。
```ini
# pytest.ini example configuration file for managing test execution and report generation with allure.
[pytest]
addopts = --alluredir=./results/allure --clean-alluredir
markers =
smoke: mark a test as part of the smoke tests suite.
regression: mark a test as part of the regression tests suite.
```
上述配置自动指定了每次运行时都清理旧的结果并将新的测试结果存储到 `./results/allure` 路径中。
#### 使用命令行工具生成测试报告
通过命令行可以方便快捷地触发带有 Allure 报告生成功能的 PyTest 运行:
```bash
pytest --alluredir=allure-results
```
这条指令会收集所有的测试案例执行情况,并将其保存至 `allure-results` 文件夹内[^2]。
#### 安装 Allure 工具及其依赖项
对于 Windows 用户来说,可以从官方 GitHub 页面下载最新版本的 Allure 压缩包并解压缩后设置系统的 PATH 变量指向该路径下的 bin 子目录;Linux 用户则可以选择直接安装 RPM/DEB 包形式发布的软件包来完成相同的操作[^3]。
另外还需要确保 Python 环境中有必要的库支持:
```bash
pip install allure-pytest
```
这一步骤确保了 PyTest 和 Allure 插件之间的兼容性和功能扩展。
#### 解决常见错误提示
当遇到类似于 `"allure" is not recognized as an internal or external command, operable program or batch file.` 的消息时,尝试关闭当前终端窗口重新打开一个新的实例再试一次操作,或者考虑以管理员权限启动 IDE (比如 PyCharm)[^4]。
阅读全文
相关推荐


















