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'])
相关推荐
htzyl2063 分钟前
CSS中,`:has()` 能帮你删掉的 4 类 JS
前端·css
心之王者7166 分钟前
Linux 进程信号:从产生、阻塞到捕捉与子进程回收
linux·服务器·网络
verohh8 分钟前
(四)配置驱动与动态渲染——从固定页面到可组合的前端架构
前端
颜进强11 分钟前
认识小微|一句话就能直接调起你小程序的微信 AI,多数人第一眼就理解错了
前端·ai编程·全栈
锐影用AI做小程序19 分钟前
uni-app X + Spring Boot 做在线工具站:6 个真实踩坑与解法
前端
掘金挖土19 分钟前
前端手摸手跑路之 AI 应用开发(十二)
前端·后端
颜进强20 分钟前
微信里冒出一个新 AI 入口,我们把接入它的每一步坑都写下来了
前端·ai编程
不要试图纠正别人20 分钟前
178 个 IPC 通道不可怕,可怕的是 preload 里那一行
前端·electron
bai27323 分钟前
Node 22 里的等待:从回调到 Promise,一次上传流程的最小记录
前端
__sjfzllv___23 分钟前
在职前端Leader学习/转行 AI Agent -DAY104
前端