pytest以函数形式形成测试用例
#coding=utf-
from __future__ import print_function #开始执行该文件时,该函数执行
def setup_module(module):
print('\nsetup_module()') #结束执行该文件时,该函数执行
def teardown_module(module):
print('teardown_module()') #单元测试函数执行之前该函数执行
def setup_function(function):
print('\nsetup_function()')
#单元测试函数执行之后该函数执行
def teardown_function(function):
print('\nteardown_function()') #case1
def test_1():
print('- test_1()') #case2
def test_2():
print('- test_2()')
输出
bogon:test macname$ pytest test.py -s
============================= test session starts ==============================
platform darwin -- Python 3.6., pytest-5.1., py-1.8., pluggy-0.12.
rootdir: /Users/macname/Desktop/test
collected items test.py
setup_module() setup_function()
- test_1()
.
teardown_function() setup_function()
- test_2()
.
teardown_function()
teardown_module() ============================== passed in .03s ===============================
另外一种方式
bogon:test macname$ pytest test.py::test_1
============================================ test session starts =============================================
platform darwin -- Python 3.6., pytest-5.1., py-1.8., pluggy-0.12.
rootdir: /Users/macname/Desktop/test
collected item test.py . [%] ============================================= passed in .01s ==============================================
bogon:test macname$ pytest test.py::test_2
============================================ test session starts =============================================
platform darwin -- Python 3.6., pytest-5.1., py-1.8., pluggy-0.12.
rootdir: /Users/macname/Desktop/test
collected item test.py . [%] ============================================= passed in .01s ==============================================
pytest以函数形式形成测试用例的更多相关文章
- pytest以函数形式的测试用例
from __future__ import print_function#pytest以函数形式形成测试用例def setup_module(module): print('\nsetup_modu ...
- pytest以类形式的测试用例
from __future__ import print_function#pytest以类形式的测试用例class TestClass: @classmethod def setup_class(c ...
- 将百度坐标转换的javascript api官方示例改写成传统的回调函数形式
改写前: 百度地图中坐标转换的JavaScript API示例官方示例如下: var points = [new BMap.Point(116.3786889372559,39.90762965106 ...
- [教程]Delphi 中三种回调函数形式解析
Delphi 支持三种形式的回调函数 全局函数这种方式几乎是所有的语言都支持的,类的静态函数也可以归为此类,它保存的只是一个函数的代码起始地址指针( Pointer ).在 Delphi 中声明一般为 ...
- pytest 12 函数传参和fixture传参数request
前沿: 有的case,需要依赖于某些特定的case才可以执行,比如,登陆获取到的cookie,每次都需要带着他,为了确保是同一个用户,必须带着和登陆获取到的同一个cookies. 大部分的用例都会先登 ...
- python单元测试框架pytest——fixture函数(类似unitest的setup和teardown)
pytest的setup和teardown函数(曾被一家云计算面试官问到过). pytest提供了fixture函数用以在测试执行前和执行后进行必要的准备和清理工作.与python自带的unitest ...
- pytest 10 skip跳过测试用例
pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者你希望失败的测试功能 skip意味着只有在满足某些条件时才希望测试通过,否则pytest应该跳过运行测试.常见事例时非win ...
- pytest自动化6:pytest.mark.parametrize装饰器--测试用例参数化
前言:pytest.mark.parametrize装饰器可以实现测试用例参数化. parametrizing 1. 下面是一个简单是实例,检查一定的输入和期望输出测试功能的典型例子 2. 标记单 ...
- pytest之将多个测试用例放在一个类中,生成唯一临时文件夹
将多个测试用例放在一个类中 简单来说就是将多个测试用例放到类中,通过pytest去管理,这和Testng很像.示例代码如下: """ 将多个测试用例放到一个类中执行 &q ...
随机推荐
- 微信小程序和asp.net core基于docker和nginx的交互
这个文章的题目起的比较长,我想实现这样一个产品: 前端是微信小程序,后端是基于docker运行的asp.net core webapi.webapi通过nginx实现的反向代理接入,nginx同样基于 ...
- 使用node+vue实现简单的WebSocket聊天功能
最近学习了一下websocket的即时通信,感觉非常的强大,这里我用node启动了一个服务进行websocket链接,然后再vue的view里面进行了链接,进行通信,废话不多说,直接上代码吧, 首先, ...
- uniapp之w-picker使用采坑
1. uniapp之w-picker使用采坑 1.1. 前言 由于我是先在index页面集合了这个组件,发现该文件内容实在太多了,不好维护,所以打算把内容一个个抽成组件,在抽w-picker时,遇到了 ...
- France Alternative forms Fraunce
Fraunce See also: france and Francë English France Alternative forms Fraunce In Fraunce, the inhabit ...
- mysql.cnf配置文件详解
参数详解 [client] #客户端设置,即客户端默认的连接参数port = 3307 #默认连接端口socket = /data/mysqldata/3307/mysql.sock #用于本地连 ...
- Mysql连接数过多、Mysql连接错误过多的问题处理
在使用Mysql的过程中,你总是会遇到这样那样的问题,每次去网上查找也相对比较麻烦,所以在此整理一下(以linux ubantu16 系统为例). ========================== ...
- Golang Web应用 创建docker镜像笔记(win 平台)
记录的是 本地编译好了再创建容器镜像的方法 ,这样子生成的镜像文件比较小,方便分发部署 win 平台需要设置golang交叉编译 生成linux可执行文件 CMD下: Set GOOS="l ...
- 【Linux】Linux下安装RabbitMQ服务
一.安装步骤 1)安装erlang yum install -y erlang2)安装rabbitmq-serveryum install -y rabbitmq-server3)开启rabbitmq ...
- 将linux和uboot集成到Android编译框架中
span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }.CodeMirror ...
- 调试用Chrome浏览器
今天写HTML页面调试时出了问题:一个页面在本地的工作空间文件夹内可以打得开,在HBuilder里用Edge打不开. 我还以为是工作空间路径出问题了,重建了好几次空间和项目.. 询问了小页,他建议以后 ...