zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Pytest----Pytest自动化测试框架中插件的安装使用和禁用方法

2023-09-14 09:12:51 时间

【原文链接】

一、插件的安装与卸载

(1)安装插件

pip install pytest-NAME

(2)卸载插件

pip uninstall pytest-NAME

二、常见的插件

  • pytest-django 为django app写的插件,与pytest集成
  • pytest-twisted 为twisted app写的插件
  • pytest-cov 测试覆盖率插件
  • pytest-xdist:支持并发执行的插件
  • pytest-instafail: 测试发生异常时上报失败插件
  • pytest-bdd:行为驱动测试
  • pytest-timeout: 超时插件
  • pytest-pep8: 代码规范检查
  • pytest-flakes:代码静态检查

更多插件参考 【插件列表】

三、加载插件

在测试文件的根目录的conftest.py中使用如下方式加载:

pytest_plugins = ["name1", "name2"]

四、查看已激活插件

$ pytest --trace-config

五、禁用插件

(1)使用如下命令禁用

pytest -p no:NAME

(2)在pytest.ini中增加如下内容:

[pytest]
addopts = -p no:NAME