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 ...
随机推荐
- 学习笔记之Coding / Design / Tool
CODING 学习笔记之代码大全2 - 浩然119 - 博客园 https://www.cnblogs.com/pegasus923/p/5301123.html 学习笔记之编程珠玑 Programm ...
- HTML5 新增文本标签
一.mark 标记文本 <mark> 标签定义带有记号的文本,表示页面中需要突出显示或高亮显示的信息. 通常在引用原文的时候使用 mark 元素,目的是引起当前用户的注意. 语法格式: & ...
- VB参考
Open 语句: 能够对文件输入/输出 (I/O). Open pathname For mode [Access access] [lock] As [#]filenumber [Len=recle ...
- Python3 解决windows里PIP下载安装速度慢
直接保存为xxx.py运行即可 自动在用户文件夹创建pip文件夹,并创建配置文件:pip.ini 从此告别pip install XXXX 下载模块速度超级慢的问题! # -*- coding: ut ...
- orcale的to_number方法
转自:https://blog.csdn.net/tiantangdizhibuxiang/article/details/81034893 TO_NUMBER函数()是Oracle中常用的类型转换函 ...
- 12 ARM汇编
Android系统采用java作为平台软件基础开发语言,NDK使Android平台可以运行C/C++代码这些代码汇编成ARM的elf可执行文件. 原生程序生成过程 经历4步:1.预处理2.编译3.汇编 ...
- 转摘jemeter学习-连接数据库之jdbc请求
JMETER连接数据库 mysql下载地址:https://dev.mysql.com/downloads/connector/j/ mysql连接器根据语言选择/J,用的是Mac,选择下载.tar. ...
- 【Axure】原型设计工具的概览与初识
软件工程综合实践第三次个人作业 作业要求:通过搜索资料和自学,了解原型设计的工具 前言: Axure是一款强大的原型设计工具,具有比较大的用户基础,在此前提下沟通.传输.修改就显得十分方便,并且在细节 ...
- Kombu源码分析(一)概述
Celery是Python中最流行的异步消息队列框架,支持RabbitMQ.Redis.ZoopKeeper等作为Broker,而对这些消息队列的抽象,都是通过Kombu实现的.Kombu实现了对AM ...
- centos 7 新机器安装部署配置
首先卸载openjdk,安装jdk 1.查看java版本 [lambert@localhost ~]$ java -version openjdk version "1.8.0_102&qu ...