#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以函数形式形成测试用例的更多相关文章

  1. pytest以函数形式的测试用例

    from __future__ import print_function#pytest以函数形式形成测试用例def setup_module(module): print('\nsetup_modu ...

  2. pytest以类形式的测试用例

    from __future__ import print_function#pytest以类形式的测试用例class TestClass: @classmethod def setup_class(c ...

  3. 将百度坐标转换的javascript api官方示例改写成传统的回调函数形式

    改写前: 百度地图中坐标转换的JavaScript API示例官方示例如下: var points = [new BMap.Point(116.3786889372559,39.90762965106 ...

  4. [教程]Delphi 中三种回调函数形式解析

    Delphi 支持三种形式的回调函数 全局函数这种方式几乎是所有的语言都支持的,类的静态函数也可以归为此类,它保存的只是一个函数的代码起始地址指针( Pointer ).在 Delphi 中声明一般为 ...

  5. pytest 12 函数传参和fixture传参数request

    前沿: 有的case,需要依赖于某些特定的case才可以执行,比如,登陆获取到的cookie,每次都需要带着他,为了确保是同一个用户,必须带着和登陆获取到的同一个cookies. 大部分的用例都会先登 ...

  6. python单元测试框架pytest——fixture函数(类似unitest的setup和teardown)

    pytest的setup和teardown函数(曾被一家云计算面试官问到过). pytest提供了fixture函数用以在测试执行前和执行后进行必要的准备和清理工作.与python自带的unitest ...

  7. pytest 10 skip跳过测试用例

    pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者你希望失败的测试功能 skip意味着只有在满足某些条件时才希望测试通过,否则pytest应该跳过运行测试.常见事例时非win ...

  8. pytest自动化6:pytest.mark.parametrize装饰器--测试用例参数化

    前言:pytest.mark.parametrize装饰器可以实现测试用例参数化. parametrizing 1.  下面是一个简单是实例,检查一定的输入和期望输出测试功能的典型例子 2.  标记单 ...

  9. pytest之将多个测试用例放在一个类中,生成唯一临时文件夹

    将多个测试用例放在一个类中 简单来说就是将多个测试用例放到类中,通过pytest去管理,这和Testng很像.示例代码如下: """ 将多个测试用例放到一个类中执行 &q ...

随机推荐

  1. Excel导出,添加有效性

    #region  添加有效性 DataTable dt = LAbll.LogisticsAccounts(DeptId); //查数据 if (dt.Rows.Count < 20) //有效 ...

  2. jsGrid使用入门

    jsGrid使用入门 原创蓝天上的一朵云 本文链接:https://blog.csdn.net/u012846041/article/details/82735811 jsGrid资源地址: http ...

  3. MySQL之SQL演练(四)

    一:准备数据 1.创建数据表 -- 创建 "京东" 数据库 create database jing_dong charset=utf8; -- 使用 "京东" ...

  4. JS this指向总结

    使用 JavaScript 开发的时候,很多开发者多多少少会被 this 的指向搞蒙圈,但是实际上,关于 this 的指向,记住最核心的一句话:哪个对象调用函数,函数里面的this指向哪个对象. 下面 ...

  5. Linux中Nginx中添加自签证书TLS

    创建自签证书TLS openssl req \ -newkey rsa: \ -x509 \ -nodes \ -keyout test.com.key \ -new \ -out test.com. ...

  6. Jmeter jmeter-server.bat 无法启动

    问题现象: 解决方法: 找到如下文件: 在目录\apache-jmeter-5.0\bin下,打开名为jmeter.properties的文件 找到server.rmi.ssl.disable=fal ...

  7. Docker 0x05: Dockerfile制作镜像

    目录 Dockerfile制作镜像 一句话什么是dockerfile dockerfile脚本指令 小结 Dockerfile制作镜像 dockerfile 可以是制作自己镜像的脚本文件,按照这个脚本 ...

  8. 自定义View(五),onLayout

    转自http://blog.csdn.net/a396901990/article/details/38129669 简介: 在自定义view的时候,其实很简单,只需要知道3步骤: 1.测量——onM ...

  9. 浅谈布隆过滤器Bloom Filter

    先从一道面试题开始: 给A,B两个文件,各存放50亿条URL,每条URL占用64字节,内存限制是4G,让你找出A,B文件共同的URL. 这个问题的本质在于判断一个元素是否在一个集合中.哈希表以O(1) ...

  10. xshell链接ubuntu16

    用xshell 链接 ubuntu16 失败 ,是因为没有装 ssh 服务 sudo apt-get install openssh-server         //安装ssh服务 ps -ef | ...