pytest简介以及命令行执行

pytest简介以及安装

pytest简介

pytest有很多强大的插件
pytest-html (生成html格式的自动化测试报告)
pytest-xdist (测试用例分布式执行,多cpu分发)
pytest-ordering (用于改变测试用例的执行顺序)
pytest-rerunfailures (用例失败后重跑)
allure-pytest (用于生成美观的测试报告)

导入第三方库

修改工具类

pytest命令方式执行

模块名必须以test_开头或_test结尾

测试类必须以Test开头,并且不能有init方法

测试方法必须以test开头

函数执行

  • 命令行执行

输入pytest

  • 主函数模式
python 复制代码
import pytest


class TestMashang:
    def test_baili(self):
        print("测试百里老师")

#主函数
if __name__ == '__main__':
    pytest.main()

pytest中的参数详解

-s:表示输出调试信息,输出print信息

-v:显示更加详细的信息

-vs:两个参数可以同时使用

-n:支持多线程或者分布式运行

  • pytest -v
  • pytest -v-n=20
  • pytest -vs --reruns=NUM:失败用例重跑,将这个模块多执行num次,最后返回结果
  • pytest -vs -x:只要有一个用例失败,测试就会停止
  • pytest -vs --maxfail=2:如果有两个测试用例失败,测试停止
  • pytest -vs --html ./reports/result.html

  • pytest -vs -k "baili":根据测试用例的部分字符串指定测试用例
相关推荐
西游音月5 小时前
(4)pytest+Selenium自动化测试-元素定位之CSS Selector定位
css·selenium·pytest
咩图14 小时前
WPF+Prism8.0.0.1909+C#创建一个桌面程序
c#·wpf·prism
雁于飞15 小时前
分布式基础
java·spring boot·分布式·spring·wpf·cloud native
oioihoii20 小时前
WPF入门指南:解析默认项目结构
wpf
极客智造1 天前
深入解析 ReactiveUI:WPF 响应式 MVVM 开发的 “终极方案”
wpf
淼_@淼2 天前
pytest-数据驱动
pytest
我的xiaodoujiao2 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 27--二次封装方法--优化断言结果
python·学习·测试工具·pytest
Macbethad2 天前
使用WPF编写一个多维度伺服系统的程序
大数据·hadoop·wpf
lingxiao168883 天前
WPF Prism框架应用
c#·wpf·prism
Macbethad3 天前
使用WPF编写一个Ethercat主站的程序
wpf