Reference Python third-party libraries in MeterSphere pre- and post-scripts

Preface

Virtualenv is a tool for creating isolated Python environments. Virtualenv creates a folder containing all the necessary executable files to use the packages required for Python projects. By
creating a Virtualenv environment on the host machine where the MeterSphere continuous testing platform is located, installing the third-party library, and mounting it into the JMeter container, you can introduce the
third-party library when executing Python scripts on the MeterSphere platform.

step

  • Install virtualenv
pip install virtualenv

注意:在同时安装了python2和python3的环境下,使用 virtualenv --copies . 创建的虚拟环境会是python3的,目前MS只支持python2,所以这里尽量使 用python2 -m virtualenv 环境名来创建

  • Install third-party packages
cd /opt/metersphere/data/
mkdir python
cd python/
virtualenv --copies .
source bin/activate

pip install xpinyin==0.5.7 -i https://pypi.tuna.tsinghua.edu.cn/simple

ll /opt/metersphere/data/python/lib/python2.7/site-packages/
  • Write Python pre- and post-scripts and verify them
import sys
sys.path.append("/opt/metersphere/data/python/lib/python2.7/site-packages")
from xpinyin import Pinyin
log.info("==========debug==========")

Guess you like

Origin blog.csdn.net/weixin_43824520/article/details/126713888