如何在jenkins容器中安装python+httprunner+pytest+git+allure(一)

背景:

API接口自动化使用python语言实现,利用httprunner框架编写自动化用例场景(执行的时候还是依赖pytest),使用jenkins自动构建git上的源代码,并产生allure报告可视化展示API执行结果。

步骤

1.进入jenkins容器

注意使用root身份进入容器

docker exec -it -uroot jenkins bash

2、具体安装步骤

复制代码
## 见上篇

 https://blog.csdn.net/dghrty_show/article/details/134445662?spm=1001.2014.3001.5502

3、验证python安装是否成功

4、安装过程中遇到的问题

bash 复制代码
##编译python执行make时,遇到如下报错导致未编译成功,报错这个会导致pip3无法使用,所以必须要解决这个
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [Makefile:1102: install] Error 1
#问题原因
当前路径下缺少zlib相关依赖包
#解决办法
     cd ~
     apt-get install zlib
 # #一定要回到python的安装路径下,/opt/py3.6次编译
     cd /opt/py3.6/
      make
      make install
bash 复制代码
##问题:执行shell脚本时,使用pytest -s -q testcases/ --alluredir=reports/ --clean-alluredir时进行jenkins构建一直报错
/tmp/jenkins138024061767095240.sh: line 3: pytest: command not found
##解决办法:
python3 -m pytest -s -q testcases/ --alluredir=reports/ --clean-alluredir
##原因:
1执行shell脚本的时候报找不到pytest命令,但是自己的库里其实已经通过pip安装了pytest,执行pip list也是可以查询到pytest的版本信息
2本来想通过设置环境变量解决,但是最终失败(如下设置)
cat  ~/.bash_profile
验证是否添加成功echo $PATH
3最终原因是:我自己通过pip去安装的pytest 并不会使其成为系统命令,所以需要通过:python -m  pytest 命令执行,使其成为系统命令
bash 复制代码
问题:在jenkins容器内安装了pytest但是就找不到pytest在哪里?
1使用whereis/which pytest无法找到
2使用 pip3 show pytest
root@localhost:/# pip3 show pytest
Name: pytest
Version: 5.4.3
Summary: pytest: simple powerful testing with Python
Home-page: https://docs.pytest.org/en/latest/
Author: Holger Krekel, Bruno Oliveira, Ronny Pfannschmidt, Floris Bruynooghe, Brianna Laugher, Florian Bruhin and others
Author-email: 
License: MIT license
Location: /usr/local/src/py3.6/lib/python3.6/site-packages
Requires: attrs, importlib-metadata, more-itertools, packaging, pluggy, py, wcwidth
Required-by: allure-pytest, httprunner, pytest-html, pytest-metadata

其实在jenkins中安装python后,安装的各种插件都是在py3.6/lib/python3.6/site-packages下的

相关推荐
bestcxx8 分钟前
0.2、AI Agent 开发中 ReAct 和 MAS 的概念
人工智能·python·dify·ai agent
fsnine28 分钟前
Python Web框架对比与模型部署
开发语言·前端·python
B站计算机毕业设计之家1 小时前
深度学习实战:python动物识别分类检测系统 计算机视觉 Django框架 CNN算法 深度学习 卷积神经网络 TensorFlow 毕业设计(建议收藏)✅
python·深度学习·算法·计算机视觉·分类·毕业设计·动物识别
程序猿小D1 小时前
【完整源码+数据集+部署教程】 【运输&加载码头】仓库新卸物料检测系统源码&数据集全套:改进yolo11-DRBNCSPELAN
python·yolo·计算机视觉·目标跟踪·数据集·yolo11·仓库新卸物料检测系统
SiYuanFeng1 小时前
《Synthetic Visual Genome》论文数据集的预处理
python·场景图
MUTA️1 小时前
python中进程和线程
python
jie*2 小时前
小杰深度学习(seventeen)——视觉-经典神经网络——MObileNetV3
人工智能·python·深度学习·神经网络·numpy·matplotlib
麦麦大数据2 小时前
F025 基于知识图谱图书可视推荐系统 vue+flask+neo4j | python编写、知识图谱可视化+推荐系统
vue.js·python·知识图谱·推荐算法·协同过滤·图书推荐
飞翔的佩奇2 小时前
【完整源码+数据集+部署教程】烟叶植株计数与分类系统源码和数据集:改进yolo11-TADDH
python·yolo·计算机视觉·目标跟踪·分类·数据集·yolo11