#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. linux memcached 的安装

    linux memcached安装yum -y install libevent libevent-deve yum list memcached yum -y install memcached m ...

  2. JavaScript 之 navigator 对象

    navigator 对象可以查看用户所使用的浏览器类型和系统平台类型. 1.userAgent  通过 userAgent 可以判断用户浏览器的类型. Chrome 浏览器效果: 2.platform ...

  3. 为什么会有jQuery、Dojo、Ext、Prototype、YUI、Zepto这么多JS包?

    目前流行的JS框架很多Dojo .Scriptaculous .Prototype .yui-ext .Jquery .Mochikit.mootools .moo.fx 等.当然还有很多我都不熟悉的 ...

  4. android启动时间慢的问题

     [转]对于Android的性能这方面评估,大部分都是有超级兔子去比跑分的,还是不能反映全面的问题.就我知道的而言,应用启动时间是很影响用户体验的一个性能方面问题. 最近的一个项目,别人都说应用启动慢 ...

  5. git 自定义log

    个人记录防止忘记 log别名: git config --global alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C ...

  6. Linux基础:sort命令总结

    本文只总结一些常用的用法,更详细的说明见man sort和sort --help. sort命令 sort命令用于串联排序指定文件并将结果写到标准输出. sort可以指定按照何种排序规则进行排序,如按 ...

  7. Httpd服务入门知识-Httpd服务常见配置案例之显示服务器版本信息

    Httpd服务入门知识-Httpd服务常见配置案例之显示服务器版本信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.httpd配置文件的组成 1>.主要组成 Globa ...

  8. C语言 dlopen dlsym

    C语言加载动态库 头文件:#include<dlfcn.h> void * dlopen(const char* pathName, int mode); 返回值 handle void ...

  9. 【使用DIV+CSS重写网站首页案例】CSS选择器

    使用表格<table></table>对网站首页进行布局有缺陷,不能拖动版块,不灵活. DIV Div是一个html的标签,单独使用没有意义,必须结合CSS使用: 是一个块级元 ...

  10. js图片转为base64的格式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...