python+pytest+allure调试过程中遇到的问题

  1. List item

有时,仅安装pytest-allure-adaptor,或者pytest-allure-adaptor、allure-pytest两个都装了,执行程序时出现以下错误:
运行报错提示:

AttributeError: module 'allure' has no attribute 'severity_level'

这很可能因为你之前安装了allure-pytest的低版本,需要卸载掉,然后安装比较新的版本;

命令执行如下:
pip uninstall pytest-allure-adaptor
pip install allure-pytest
还可以看下是不是自己有allure-pytest库,需要卸载这个库。

  1. List item
No module named '_pytest.resultlog'

pytest版本:6.2.1
pytest-rerunfailures版本:9.1.0
pytest-xdist版本:2.2.0

原因是因为pytest-rerunfailures导入,_pytest.resultlog但该模块已在 pytest-dev/pytest@ef946d5被删除
结果,不再可以pytest-rerunfailures与pytest 6.1.0以上的版本一起使用。

解决办法:
①升级pytest-rerunfailures版本到9.1.1
②卸载pytest-rerunfailures使用pytest-reportlog代替
③降低pytest版本到6.1.0以下

  1. List item
pluggy.PluginValidationError: Plugin 'html' could not be loaded: (pytest 3.6.0 (c:\users\lilingyun01\appdata\local\programs\python\python37\lib\site-packages), Requirement.parse('pytest!=6.0.0,>=5.0'))!
  1. List item
INTERNALERROR>     pytest.allure._allurelistener = testlistener
INTERNALERROR> AttributeError: module 'pytest' has no attribute 'allure'

原因可能由于:因为pytest-allure-adaptor库基本被python3放弃了,运行很不友好,所以报错
解决方法

pip uninstall pytest-allure-adaptor
pip install allure-pytest
  1. List item

执行命令:pytest “test.py” --alluredir=report

unrecognized arguments: --alluredir .\reports\xml
  inifile: None
  rootdir: C:\Users\lilingyun01\Desktop\uiTest

查找问题原因
直接通过错误信息看,是因为allure-pytest插件未安装,但是在pycharm的python虚拟环境中已经安装好了。
但是有一个关键信息是,我第一次执行这条命令的时候,命令正常执行了,而且report中也生成了数据,
据此,怀疑和环境有关。查看了python --version发现版本确实为3.7,查看了pip --version,指向的python也为3.7
带着疑问,google后,发现有人也遇到类似问题,也是在本地环境中装了2个以上的python版本。一样的代码,
网友换了一台只有一个python版本的电脑,问题不再出现
结论:在命令行执行运行pytest “test.py” --alluredir=report命令时,可能以某种方式使用了未安装allure-pytest
的python版本,也就是说命令行运行pytest命令时,使用的python环境不是Pycharm中指定的python虚拟环境

解决办法
a. 直接在工程中新建run_pytest.py文件,在main函数中去运行pytest命令

import pytest
if __name__ == '__main__':
    command_line = ["-s", "./tests/test1/test1.py", "--alluredir=report"]
    pytest.main(command_line)

运行main后,可以在report中正常生成allure报告需要的数据
b.改变pytest命令的运行格式
在命令行执行pytest命令有三种方式:
pytest
py.test
python -m pytest
使用第三种方式也可以解决问题
在这里插入图片描述

  1. List item
AMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe

d = yaml.load(cfg,Loader=yaml.FullLoader) # 用load方法转字典
添加了Loader=yaml.FullLoader

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuer011

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值