解决mac端pycharm执行allure命令报错:returned non-zero exit status 127

1、错误代码:

python 复制代码
    def generate_allure_report(self):
        common = ["allure", "generate", "./reports/allure/temps", "-o", "./reports/allure/report", "--clean"]
        # common = ['allure', '--version']
        try:
            # 使用subprocess.run来执行命令
            result = subprocess.run(
                common,
                shell=True, # mac端使用时需要注释掉,否则报错
                check=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                text=True
            )
            logutil.info("Allure report generated successfully.")
            logutil.info("Output:", result.stdout)

2、代码背景

上述代码是在pytest执行完成后执行allure命令生成测试报告,本身可以通过os.system执行,但是为了符合目前新的规范,个人选择改用了subprocess.run()的方式去写入命令。

本来在window端执行没有任何问题,但是在mac端执行时,则直接报错:

returned non-zero exit status 127

3、报错原因

首先,我在命令行手动执行allure命令是没问题的,所以确定allure安装配置正确。刚开始以为是版本问题,后来切换了其他版本发现也是一样报错,于是百度了一下,发现居然没有人发同样的问题上来,最终,ai了一下,发现了正确原因:

【

在 macOS 上,subprocess.run 的 shell=True 参数可能导致命令解析问题,尤其是当 allure 命令依赖于环境变量时。

】

但是原因也不具体,这里解决问题,不探究底层了。

4、解决方式

把shell=True这行注释掉后,就可以正常调用执行了。

所以最终正确代码如下:

python 复制代码
    def generate_allure_report(self):
        common = ["allure", "generate", "./reports/allure/temps", "-o", "./reports/allure/report", "--clean"]
        # common = ['allure', '--version']
        try:
            # 使用subprocess.run来执行命令
            result = subprocess.run(
                common,
                # shell=True, # mac端使用时需要注释掉,否则报错
                check=True,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                text=True
            )
            logutil.info("Allure report generated successfully.")
            logutil.info("Output:", result.stdout)
相关推荐
全栈探索者15 小时前
一枚 162MB 的挂件,改写一只猫的画风:LoRA 实战——风格定制与人脸保持
人工智能·macos·lora·aigc·stablediffusion·comfyui
喆星时瑜15 小时前
探索 Anaconda 中的 JupyterLab、Jupyter Notebook、iPython 解释器(Qt 控制台)和 Spyder IDE
ide·jupyter·ipython
福大大架构师每日一题16 小时前
ollama v0.40.11发布:macOS原生语音生成上线,d3决策模型正式加入
macos·策略模式
小天源21 小时前
智叟云集系统:便携部署、MAC 授权与交付排障
macos
Joy T1 天前
voice-dump-to-todo:把混乱的语音整理成可执行待办,一个实用的 Agent Skill
ide·macos·语音识别·xcode·任务管理·自研skill
人工智能导论实践课1 天前
【GUI桌面开发3】PyCharm配置外部工具
ide·python·pycharm
JPower_mr.g1 天前
SmartCall v1.0.9 发布:智能体知识库上线,让 AI 客服先查资料再回答
java·ide·人工智能·macos·架构·开源·xcode
轻口味1 天前
启元无真机二开实战:先在Mac上养一台Q1——官方URDF到MuJoCo数字孪生的完整链
macos·具身智能·mujoco·启元机器人
Dev _1 天前
PyCharm旧进程仍在后台运行,导致新实例无法启动或连接
ide·python·pycharm
无巧不成书02182 天前
Tomcat部署JSP文件完整指南:手动部署+IDEA工程化实现 附404访问错误全排查
java·ide·windows·tomcat·intellij-idea·js