You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Action自托管Windows Runner上pytest无输出仅返回退出码1

Windows自托管Runner上pytest无输出仅返回exit code 1的解决方案

问题详情

在Windows Server 2019的自托管GitHub Actions Runner中执行pytest时,无任何输出,仅返回exit code 1,开启ACTIONS_RUNNER_DEBUG调试模式后仍无额外日志。环境配置:

  • 使用actions/setup-python@v4安装Python 3.9.13
  • 通过python -m pip install -e '.[dev]'安装包含pytest的开发依赖
  • 执行命令pytest --version时,Action日志如下:
Run pytest --version
  pytest --version
  shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'"
  env:
    ACTIONS_RUNNER_DEBUG: true
  
    pythonLocation: C:\Users\User1\GHA_abs\_work\_tool\Python\3.9.13\x64
    PKG_CONFIG_PATH: C:\Users\User1\GHA_abs\_work\_tool\Python\3.9.13\x64/lib/pkgconfig
    Python_ROOT_DIR: C:\Users\User1\GHA_abs\_work\_tool\Python\3.9.13\x64
    Python2_ROOT_DIR: C:\Users\User1\GHA_abs\_work\_tool\Python\3.9.13\x64
    Python3_ROOT_DIR: C:\Users\User1\GHA_abs\_work\_tool\Python\3.9.13\x64
Error: Process completed with exit code 1.

排查与修复步骤

  • 直接指定Python解释器执行pytest:避免PowerShell环境下的路径或别名冲突,调用setup-python安装的Python执行:
    & $env:pythonLocation\python.exe -m pytest --version
    
  • 验证pytest安装状态:确认依赖安装成功,检查pytest是否存在于当前环境:
    & $env:pythonLocation\python.exe -m pip list | findstr pytest
    & $env:pythonLocation\python.exe -c "import pytest; print(pytest.__file__)"
    
    若输出为空或报错,重新强制安装依赖:
    & $env:pythonLocation\python.exe -m pip install -e '.[dev]' --force-reinstall
    
  • 捕获stderr输出:在PowerShell中重定向标准错误到标准输出,查看隐藏的错误信息:
    pytest --version 2>&1
    # 或通过Python调用时捕获
    & $env:pythonLocation\python.exe -m pytest --version 2>&1
    
  • 检查Runner权限:确保Runner服务账户(User1)对Python安装目录、工作目录拥有读写权限,尤其是可编辑安装的包目录。
  • 临时放宽PowerShell执行策略:避免脚本执行被系统限制:
    Set-ExecutionPolicy Bypass -Scope Process -Force
    

内容的提问来源于stack exchange,提问作者ikamen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 16:32:32