python 虚拟环境调用allure报错:FileNotFoundError: [WinError 2] 系统找不到指定的文件

一、遇到的问题

python代码调用命令行 allure命令报错,提示找不到allure这个命令。python虚拟环境中已经安装了pytest-allure

代码如下:

python 复制代码
import subprocess

if __name__ == "__main__":
    # retcode = pytest.main()

    subprocess.call(['pytest', '--alluredir=./report/allure'])
    subprocess.call(['allure', 'serve', './report/allure'])

报错如下:

python 复制代码
Traceback (most recent call last):
  File "D:\project\python\pytestDemo\main.py", line 17, in <module>
    subprocess.call(['allure', 'serve', './report/allure'])
  File "C:\Users\liyuanhong\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 389, in call
    with Popen(*popenargs, **kwargs) as p:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\liyuanhong\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\liyuanhong\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1538, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

查看了我的python虚拟环境: venv/Scripts 目录下确实没有 allure 命令

二、解决方法

下载 allure 命令行工具

下载地址:Central Repository: io/qameta/allure/allure-commandline

选择对应的版本下载,解压到项目目录如下:

创建一个 allure.bat的超链接,将超链接文件拷贝到 venv/Scripts 目录下

修改代码如下即可:

python 复制代码
import subprocess

if __name__ == "__main__":
    # retcode = pytest.main()

    subprocess.call(['pytest', '--alluredir=./report/allure'])
    subprocess.call(['allure.bat', 'serve', './report/allure'])
相关推荐
kyriewen29 分钟前
2026 年了,这 6 个 npm 包可以卸载了——浏览器原生 API 已经能替代
前端·javascript·npm
aqi002 小时前
15天学会AI应用开发(八)使用向量数据库实现RAG功能
人工智能·python·大模型·ai编程·ai应用
Csvn3 小时前
`functools.lru_cache` —— 一行代码搞定缓存加速
后端·python
Csvn3 小时前
Monorepo 迁移血泪史:从 Multi-Repo 到 Turborepo,这 3 个坑我帮你踩完了
前端
星栈3 小时前
Dioxus 多页面怎么做:`dioxus-router`、嵌套路由、`Outlet` 和页面组织,一篇给你讲顺
前端·rust·前端框架
zzzzzz3103 小时前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
用户987409238873 小时前
用 Remotion + edge-tts 打造中文教学视频全自动流水线
前端
风骏时光牛马3 小时前
Less前端工程化实战:变量混合器与项目样式分层落地
前端
假如让我当三天老蒯4 小时前
Options API(选项式 API) 和 Composition API(组合式 API)
前端·vue.js·面试