当前位置:网站首页>pytest学习--base
pytest学习--base
2022-07-02 06:36:00 【迷途~知返】
pytest单元测试框架
单元测试是指在软件开发过程中,针对软件的最小单位(函数、方法)进行正确的检查测试
单元测试框架:
java:junit和testing
python:unnitest和pytest
单元测试框架主要做什么
- 测试发现:从多个文件里面去找找到我们的测试用例
- 测试执行:按照一定的顺序和规则去执行,并生成结果
- 测试判断:通过断言判断预期结果和世界结果的差异
- 测试报告:统计测试进度,耗时,通过率,生成测试报告
单元测试框架和自动化测试框架有什么关系 - 什么是自动化测试框架:去完成整个系统的完善的代码的框架,封装自动化的基础模块,管理模块
- 作用
- 提高测试效率,较低维护成本
- 减少人工干预,提高测试的准确性,增加代码的重用性
- 核心思想是让不懂代码的人也能通过这个框架去实现自动化测试
- pytest单元测试和自动化测试框架的关系
- 单元测试框架:
- pom设计模式
- 数据驱动
- 关键字驱动
- 全局配置文件的封装
- 日志监控
- selienium,requests
- 断言
- 报告邮件
pytest简介
1、pytest是一个非常成熟的python单元测试框架,比unnitest简单
2、pytest可以和selinum,requests,appinum结合实现web自动化,接口自动化,APP自动化
3、pytest可以实现测试用例的跳过以及returns失败用例的重试
4、pytest可以和allture生成非常美观的测试报告
5、pytest可以和jenkins持续集成
6、pytest有很多非常强大的插件,并且这些插件能够实现很多的使用的操作
- pytest
- pytest-html(生成html格式的自动化测试报告)
- pytest-xdist 测试用例分步执行,多cpu分发
- pytest-ordering 用于改变用例的执行顺序
- pytest-returning 用例失败后重跑
- allure-pytest 用于生成美观的测试报告
- 放到requirement.txt文件中通过pip install -r requirement.txt
使用pytest,默认的测试用例的规则以及基础应用
- 1、模块名必须以test_或者_test结尾
- 2、测试类必须以Test开头,不能有__init__方法
- 3、测试方法必须以test开头
pytest测试用例的运行方式
主函数模式运行
-运行所有:pytest.main()
指定模块:pytest.main([‘-vs’,‘test_login.py’])
指定目录运行:pytest.main([‘-vs’,‘./interface/test_01_inter.py’])
通过nodeid指定用例运行:node由模块名,分隔符,类名,方法名,函数名组成命令行模式运行
-运行所有pytest
指定模块运行 pytest -vs test_login.py
指定目录运行:pytest -vs ./interface/test_01_inter.py
参数详解:
-s:输出调试的信息包括print打印的信息
-v:显示更加详细的信息
-vs:这两个参数一起使用
-n:支持多线程或者分布式运行测试用例
pytest -vs ./testcase/test_login.py -n 2
-x:表示只要有一个用例报错,那么测试停止
-k:根据测试用例的部分字符串指定测试用例
如:pytest -vs ./testcase -k “ao”
–html 生成html报告
通过读取pytest.ini配置文件运行
-pytest.ini这个文件他是pytest单元测试矿建的核心配置文件
-位置:一般放在项目的根目录
-编码:ASCII编码,可以使用nopad++修改编码格式
-作用:改变pytest默认的行为
-运行规则:不管是主函数的运行模式,命令行模式运行,都回去读取这个配置文件
[pytest]
addopts=-vs # 命令行参数是
testpaths=./testcase # 测试用例的路径
python_files = test_*.py # 模块名的规则
python_classes = Test* # 类名的规则
python_functions = test # 方法名的规则
marks =
smoke:冒烟用例
usermanage:用户管理模块
六、pytest执行测试用例的顺序:
默认执行方式是从上到下依次执行
加标记执行
分组执行(冒烟,接口,web)
smoke:猫眼用例,分布在各个模块里面
pytest -m “smoke”
pytest -m "smoke or usermanage"t
跳过测试用例
(1)无条件跳过
pytest.mark.skip(reason="xxxx")
class TestCar:
age = 20
@pytest.mark.skip(reason="xxxxxx")
def test_01_car(self):
print("this is old car")
(2)有条件跳过
class TestCar:
age = 20
@pytest.mark.skipif(age>=18,reason="xxxxxxx")
def test_01_car(self):
print("this is old car")
pytest.mark.skipif(age>=18,reason="xxxxxxx")
边栏推荐
- Project practice, redis cluster technology learning (VII)
- 2837xd代码生成模块学习(4)——idle_task、Simulink Coder
- 虚幻材质编辑器基础——如何连接一个最基本的材质
- 2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
- Edge computing accelerates live video scenes: clearer, smoother, and more real-time
- 阿里云Prometheus监控服务
- This monitoring system makes workers tremble: turnover intention and fishing can be monitored. After the dispute, the product page has 404
- Blender体积雾
- 2837xd代码生成模块学习(1)——GPIO模块
- Blender摄像机环绕运动、动画渲染、视频合成
猜你喜欢

UE4 night lighting notes

Blender volume fog

Ctrip starts mixed office. How can small and medium-sized enterprises achieve mixed office?
![[unreal] animation notes of the scene](/img/97/dafde0377b7c4337e1775db64ba6a4.png)
[unreal] animation notes of the scene

Configuration programmée du générateur de plantes du moteur illusoire UE - - Comment générer rapidement une grande forêt

2837xd代码生成模块学习(1)——GPIO模块

Illusion -- Animation blueprint, state machine production, character walking, running and jumping action

Blender多镜头(多机位)切换

【虚幻4】从U3D到UE4的转型之路

Applet development summary
随机推荐
Blender camera surround motion, animation rendering, video synthesis
虚幻AI蓝图基础笔记(万字整理)
2.14 is it Valentine's day or Valentine's day when the mainstream market continues to fluctuate and wait for changes?
Feature (5): how to organize information
High level application of SQL statements in MySQL database (II)
2837xd code generation module learning (4) -- idle_ task、Simulink Coder
测试--面试题总结
Remember a simple Oracle offline data migration to tidb process
滲透測試的介紹和防範
【leetcode】33. Search rotation sort array
【Unity3D】制作进度条——让Image同时具有Filled和Sliced的功能
MySQL -- time zone / connector / driver type
渗透测试的介绍和防范
【虚幻】过场动画笔记
Vscode auto format
2837xd代码生成模块学习(3)——IIC、eCAN、SCI、Watchdog、eCAP模块
Skywalking theory and Practice
Large neural networks may be beginning to realize: the chief scientist of openai leads to controversy, and everyone quarrels
【虚幻4】UMG组件的简介与使用(更新中...)
2837xd code generation - stateflow (3)