1.Python3 run.py 无法运行pytest框架
服务器安装:
pip install pytest
。我也能用Python导入库
解决方法:
python -m pytest
python3 -m pytest --html=%s/report.html --self-contained-html --alluredir %s
2.allure运行报错 “ValueError: option names {'--alluredir'} already added”
问题排查:
依赖包冲突
pytest-allure-adaptor与allure-pytest的alluredir都被引用造成冲突
解决办法:
需要卸载不用的包 :pip uninstall pytest-allure-adaptor
3.脚本执行完成后 不生成allure 报告
问题排查:
通过打印运行时系统PATH变量,发现Python在运行的时候 没有加载系统环境变量
解决办法:
代码内手动增加环境变量写入,使运行的时候自动添加运行环境变量
path = "/usr/bin:/usr/local/sbin:/usr/sbin:/home/jenkinsx/.local/bin:/home/jenkinsx/bin:/home/jenkinsx/workspace/allure-2.13.8/bin"
shell.invoke(cmd, env={"PATH": path})
class Shell:
@staticmethod
def invoke(cmd, env={}):
output, errors = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env).communicate()
o = output.decode("utf-8")
return o