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

Jenkins执行pytest命令未识别且pg_config文件缺失如何解决?

解决方案

一、修复Jenkins Windows批处理脚本

你的原有脚本仅创建了虚拟环境,未执行激活、依赖安装步骤,是pytest无法识别的直接原因,修改后的完整脚本如下:

echo '#### Create Virtual Environment ####'
python -m venv .UIAutomation/venv
echo '#### Activate Virtual Environment ####'
call .UIAutomation\venv\Scripts\activate.bat
echo '#### Upgrade base tools ####'
python -m pip install --upgrade pip setuptools wheel
echo '#### Install dependencies ####'
pip install -r ./UIAutomation/requirements.txt
echo '#### Run tests ####'
pytest -s -v --alluredir=.UIAutomation/reports ./UIAutomation/tests --env=staging --browser=chrome 

注意:Windows批处理中调用虚拟环境激活脚本必须加call命令,否则后续命令不会在虚拟环境上下文执行。


二、解决pg_config缺失导致的psycopg2安装失败

该报错是因为psycopg2源码编译依赖PostgreSQL的pg_config可执行文件,可任选以下一种方案修复:

  • 方案1(优先推荐):将requirements.txt中的psycopg2==2.8.6替换为psycopg2-binary==2.8.6,该包为预编译的二进制版本,无需本地编译环境,也不需要pg_config依赖。
  • 方案2:在Jenkins slave机器安装PostgreSQL官方安装包,将PostgreSQL安装路径下的bin目录(包含pg_config.exe)添加到系统环境变量PATH中,重启Jenkins agent服务后重新执行任务即可。

三、告警修复

warning: manifest_maker: standard file '-c' not found 为setuptools版本过低导致的临时告警,脚本中已添加升级setuptools的步骤,执行后告警会自动消失。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 19:06:01