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

一、遇到的问题

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

代码如下:

import subprocess

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

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

报错如下:

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 目录下

修改代码如下即可:

import subprocess

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值