python + pytest 基本使用方法(Fixture)
#firtures通常用来对测试方法、测试函数、测试类和整个测试文件进行初始化或还原测试环境
# setup_module/teardown_module:在当前文件中,在所有测试用例执行之前与之后执行,只执行一次;
# setup_function/teardown_function:在每个测试函数之前与之后执行;
# setup/teardown:在每个测试函数之前与之后执行;
# 在当前文件下打开cmd窗口执行:pytest -s test_fixtures_01.py
#功能函数
def multiply(a,b):
return a * b
#===============Firtures=============
def setup_module(module):
print('setup_module------------>')
def teardown_module(module):
print('teardown_module--------->')
def setup_function(function):
print('setup_function---------->')
def teardown_function(function):
print('teardown_function-------->')
def setup():
print('setup---------->')
def teardown():
print('teardown------->')
#==========测试用例==========
def test_multiply_3_4():
print('test_numbers_3_4')
assert multiply(3,4) == 12
def test_multiply_a_3():
print('test_numbers_a_3')
assert multiply('a',3) == 'aaa'
#pytest 是支持使用测试类的,同样必须以Test开头,注意首字母大写。
# setup_class/teardown_class:在当前测试类的开始与结束时执行,只执行一次;
# setup_module/teardown_module:在每个测试方法开始与结束时执行;
# setup/teardown:在每个测试方法开始与结束时执行;
# 在当前文件下打开cmd窗口执行:pytest -s test_fixtures_02.py
#功能函数
def multiply(a,b):
return a * b
class TestMultiply:
#===============Firtures=============
@classmethod
def setup_class(cls):
print('setup_class------------>')
@classmethod
def teardown_class(cls):
print('teardown_class--------->')
def setup_module(self,module):
print('setup_module------------>')
def teardown_module(self,module):
print('teardown_module--------->')
def setup(self):
print('setup---------->')
def teardown(self):
print('teardown------->')
#==========测试用例==========
def test_multiply_5_6(self):
print('test_numbers_5_6')
assert multiply(5,6) == 30
def test_multiply_b_3(self):
print('test_numbers_b_3')
assert multiply('b',3) == 'bbb'
python + pytest 基本使用方法(Fixture)的更多相关文章
- python + pytest基本使用方法(拓展库)
一.测试钩子配置文件 import pytest# conftest.py 是pytest特有的本地测试配置文件;# 既可以用来设置项目级别的Fixture,也可用来导入外部插件,还可以指定钩子函数# ...
- python + pytest基本使用方法(运行测试&测试报告)
import pytest# 1.运行名称中包含某字符串的测试用例#名称中含add 的测试用例# 执行: pytest -k add test_assert.py# 2.减少测试的运行冗长# 执行: ...
- python + pytest基本使用方法(参数化)
import pytestimport math#pytest 参数化#'base,exponent,expected'用来定义参数的名称.# 通过数组定义参数时,每一个元组都是一条测试用例使用的测试 ...
- python + pytest基本使用方法(断言)
#pytest 的基本用法# 安装: pip install pytest#在当前目录下运行 : 输入 pytest# 1.断言#功能:用于计算a与b相加的和def add(a,b): return ...
- python pytest测试框架介绍二
在介绍一中简单介绍了pytest的安装和简单使用,接下来我们就要实际了解pytest了 一.pytest的用例发现规则 pytest可以在不同的函数.包中发现用例,发现的规则如下 文件名以test_开 ...
- python:pytest中的setup和teardown
原文:https://www.cnblogs.com/peiminer/p/9376352.html 之前我写的unittest的setup和teardown,还有setupClass和teardow ...
- Python+Pytest+Allure+Git+Jenkins接口自动化框架
Python+Pytest+Allure+Git+Jenkins接口自动化框架 一.接口基础 接口测试是对系统和组件之间的接口进行测试,主要是效验数据的交换,传递和控制管理过程,以及相互逻辑依赖关系. ...
- Pytest(3)fixture的使用
fixture的优势 Pytest的fixture相对于传统的xUnit的setup/teardown函数做了显著的改进: 命名方式灵活,不局限于 setup 和teardown 这几个命名 conf ...
- python+pytest接口自动化(11)-测试函数、测试类/测试方法的封装
前言 在python+pytest 接口自动化系列中,我们之前的文章基本都没有将代码进行封装,但实际编写自动化测试脚本中,我们都需要将测试代码进行封装,才能被测试框架识别执行. 例如单个接口的请求代码 ...
随机推荐
- 反应式系统实现MQTT客户机
反应式系统实现MQTT客户机 Implementing an MQTT client for reactive systems MQTT Reactive是从LiamBindle的MQTT-C库派生的 ...
- node和gulp版本的坑
现在node版本最新的稳定版在14+ 然后我在接手项目的时候使用gulp打包,怎么也打包不了,这个问题纠结了挺久,然后百度了下,发现版本的问题 node 12+ 以上的版本不兼容 gulp 3的版本 ...
- 七、SSL加密网站(待解决)
keytool -genkeypair -alias tomcat -keyalg RSA -keystore /usr/local/tomcat/keystore //创建私钥和证书文件提示输入密 ...
- Centos 安装 Influxdb + Chronograf
安装 Influxdb 1:下载安装包 官网下载地址 https://portal.influxdata.com/downloads/# wget https://dl.influxdata.com ...
- 【NX二次开发】Block UI 双精度表
属性说明 常规 类型 描述 BlockID String 控件ID Enable Logical 是否可操作 Group Logical ...
- NX二次开发-克隆操作
模板文件: 克隆替换字符串: 1 #include "Text.h" 2 extern DllExport void ufsta(char *param, int *returnC ...
- 使用 Docker 部署 Node 应用
容器将应用与环境打包整合,解决了应用外部依赖的痛点,打包后通过窗口可方便地部署到任意环境,用过就知道很香. 创建示例应用 以 NestJS 为例,先创建一个示例应用. $ npm i -g @nest ...
- [Azure DevOps] 编译时自动修改版本号
1. 需求 在使用 Pipeline 自动化 CI/CD 流程的过程中,我还还需要自动修改程序集的版本号.这个功能 EdiWang 和LeoLaw 都写文章讲解过做法.不过我的项目基本都是 .Net ...
- 6.6考试总结(NOIP模拟4)
前言 考试这种东西暴力拉满就对了QAQ T1 随 题解 解题思路 DP+矩阵乘(快速幂)+数论 又是一道与期望无关的期望题,显然答案是 总情况/情况数(\(n^m\)). 接下来的问题就是对于总情况的 ...
- Flask一分钟Mock一个API
如果安装了Python,并且安装了Flask: pip install flask 那么就可以在短短一分钟内Mock出来一个API,而且只需要用到一个文件. 彻底告别在线Mock网站无法指定请求方法, ...