自动化工具 httprunner 运行报错,有人遇到过么?何解 (已解决)

我去催饭 · 2020年09月10日 · 最后由 我去催饭 回复于 2020年09月11日 · 5131 次阅读

环境:python3.7.5
Httprunner:3.1.4
在我本机是运行 ok 的,但是放 jenkins 上执行就报了这个错误,重新安装也没有用。有大佬知道怎么回事吗?

2020-09-10 19:12:02.255 | INFO | httprunner.make:__make:512 - make path: /var/lib/jenkins/workspace/cos_qa_tools/cos_api_test/testsuites/cos_old/login_test.py
2020-09-10 19:12:02.255 | INFO | httprunner.make:format_pytest_with_black:170 - format pytest cases with black ...
2020-09-10 19:12:02.279 | ERROR | httprunner.make:format_pytest_with_black:189 -
missing dependency tool: black
install black manually and try again:
$ pip install black

Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
Build step 'Execute shell' marked build as failure
Finished: FAILURE

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 7 条回复 时间 点赞

jenkins 所在的机子装个 black 试下

洋葱 #7 回复

装了,pip list 查看是有这个模块的,不知为啥,怀疑是 python 版本不兼容问题,打算明天卸了 python3.7.5 换成 3.8,然后再装一下 httprunner 看看

jenkins 没有配置环境变量

环境建议换 3.6,稳

问题还是没解决,现在 jenkins 运行构建就会提示这个错误,直接在 jenkins 的服务器上运行 hrun xxx.py 是没问题的
missing dependency tool: black
install black manually and try again:

这是 jenkins 的执行日志:
开始执行任务
/var/lib/jenkins/workspace/cos_qa_tools/cos_api_test/testsuites/cos_old/login_test.py
上面是执行的 case 路径,下面执行任务
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: black in /usr/local/python3/lib/python3.7/site-packages (20.8b1)
Requirement already satisfied: mypy-extensions>=0.4.3 in /usr/local/python3/lib/python3.7/site-packages (from black) (0.4.3)
Requirement already satisfied: typing-extensions>=3.7.4 in /usr/local/python3/lib/python3.7/site-packages (from black) (3.7.4.3)
Requirement already satisfied: regex>=2020.1.8 in /usr/local/python3/lib/python3.7/site-packages (from black) (2020.7.14)
Requirement already satisfied: pathspec<1,>=0.6 in /usr/local/python3/lib/python3.7/site-packages (from black) (0.8.0)
Requirement already satisfied: typed-ast>=1.4.0 in /usr/local/python3/lib/python3.7/site-packages (from black) (1.4.1)
Requirement already satisfied: click>=7.1.2 in /usr/local/python3/lib/python3.7/site-packages (from black) (7.1.2)
Requirement already satisfied: appdirs in /usr/local/python3/lib/python3.7/site-packages (from black) (1.4.4)
Requirement already satisfied: toml>=0.10.1 in /usr/local/python3/lib/python3.7/site-packages (from black) (0.10.1)
2020-09-11 15:07:16.964 | INFO | httprunner.make:__make:512 - make path: /var/lib/jenkins/workspace/cos_qa_tools/cos_api_test/testsuites/cos_old/login_test.py
2020-09-11 15:07:16.964 | INFO | httprunner.make:format_pytest_with_black:170 - format pytest cases with black ...
2020-09-11 15:07:16.971 | ERROR | httprunner.make:format_pytest_with_black:189 -
missing dependency tool: black
install black manually and try again:
$ pip install black

Sentry is attempting to send 0 pending error messages
Waiting up to 2 seconds
Press Ctrl-C to quit
结束任务
Finished: SUCCESS

我去催饭 关闭了讨论 09月11日 19:55
我去催饭 重新开启了讨论 09月11日 19:55

问题解决了:是 jenkins 执行的时候没有获取到 python 的 path。我通过 echo ${PATH}获得


显然,他没有读取到我的 python 环境变量。于是最后解决方案就是:在构建命令里加入相关环境变量的 export 命令
PATH=$PATH:$HOME/bin:/user/local/python3:/usr/local/python3/lib/python3.7/site-packages:/usr/local/python3/bin
export black=/usr/local/python3/bin
export PATH
export PYTHONPATH=/user/local/python3,/usr/local/python3/lib/python3.7/site-packages,/usr/local/python3/bin
source $PATH
问题就解决了,和 httprunner 并没有关系

我去催饭 关闭了讨论 09月11日 19:58
我去催饭 重新开启了讨论 09月11日 20:06
我去催饭 关闭了讨论 09月13日 23:17
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册