from __future__ import print_function
#pytest以类形式的测试用例
class TestClass:
@classmethod
def setup_class(cls):
print('\nsetup_class()') @classmethod
def teardown_class(cls):
print('teardown_class()') def setup_method(self,method):
print('\nsetup_method()') def teardown_method(self,method):
print('\nteardown_method()') def test_1(self):
print('- test_1()') def test_2(self):
print('- test_2()')
运行:
##输出print内容
 pytest -s test_class.py 或者 pytest --capture=no  test_class.py
结果:

======================================================================================== test session starts ========================================================================================
platform darwin -- Python 3.7.3, pytest-4.4.0, py-1.8.0, pluggy-0.9.0
rootdir: /Users/likuanrong/PycharmProjects/work
plugins: metadata-1.8.0, html-1.20.0
collected 2 items

test_class.py
setup_class()

setup_method()
- test_1()
.
teardown_method()

setup_method()
- test_2()
.
teardown_method()
teardown_class()

===================================================================================== 2 passed in 0.03 seconds ======================================================================================

pytest以类形式的测试用例的更多相关文章

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

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

  2. pytest以函数形式形成测试用例

    #coding=utf- from __future__ import print_function #开始执行该文件时,该函数执行 def setup_module(module): print(' ...

  3. javascript多态 - 类形式实现demo

    /* *多态 * 对传入的参数做判断以实现多种调用方式 */ //类形式实现 function Add(){ function zero(){ return 10; } function one(nu ...

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

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

  5. Pytest从测试类外为测试用例动态注入数据

    今天Nelly问我Pytest能不能支持从TestClass类外传入参数?从类外批量传入各个test方法需要的参数.因为数据文件可能有很多情况,不方便依次匹配. 然而又必须用类对用例进行归类及复用,数 ...

  6. pytest 10 skip跳过测试用例

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

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

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

  8. WebService:java配置类形式发布WebService接口及遇见的问题总结

    配置WebService前需要以下依赖jar包 #版本只供参考,具体看项目 <dependency> <grouId>org.apache.cxf</grouId> ...

  9. python pytest测试框架介绍二

    在介绍一中简单介绍了pytest的安装和简单使用,接下来我们就要实际了解pytest了 一.pytest的用例发现规则 pytest可以在不同的函数.包中发现用例,发现的规则如下 文件名以test_开 ...

随机推荐

  1. Codeforces Round #513解题报告(A~E)By cellur925

    我是比赛地址 A:Phone Numbers $Description$:给你一串数字,问你能组成多少开头为8的11位电话号码. $Sol$:统计8的数量,与$n$%11作比较. #include&l ...

  2. the little schemer 笔记(8)

    第八章 lambda the ultimate 还记得我们第五章末的rember和insertL吗 我们用equal?替换了eq? 你能用你eq?或者equal?写一个函数rember-f吗 还不能, ...

  3. 跟我一起玩Win32开发(21):复制&粘贴&剪贴板操作

    我要提醒一下大家,看了我的博文学到的知识,千万不要用于实际开发,不然你会被你的上司骂:“妈的,这些东西哪来的,从来没有人这样做过.”不信你试试,脑细胞被冻结的经理或者技术总监们肯定会这样说的. 如果是 ...

  4. AtCoder Grand Contest 016 C - +/- Rectangle

    题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_c 题目大意: 给定整数\(H,W,h,w\),你需要判断是否存在满足如下条件的矩阵,如果存在 ...

  5. AtCoder Regular Contest 074 F - Lotus Leaves

    题目传送门:https://arc074.contest.atcoder.jp/tasks/arc074_d 题目大意: 给定一个\(H×W\)的网格图,o是可以踩踏的点,.是不可踩踏的点. 现有一人 ...

  6. Elipse 无法启动问题(转)

    来源: <http://www.cnblogs.com/coding-way/archive/2012/10/17/2727481.html> 当选择完workspace之后,eclips ...

  7. 牛客网Java刷题知识点之自动拆装箱

    不多说,直接上干货! https://www.nowcoder.com/ta/review-java/review?query=&asc=true&order=&page=5 ...

  8. maven-ali镜像网站setting.xml

    简述 使用maven管理jar包的时候,有可能会有网络限制,要解决的这个问题的话可以使用ali的镜像网站. 创建文件 创建settings.xml,内容如下 <settings xmlns=&q ...

  9. STM32 modbus CRC16校验

    typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef int int32_t; const uint16_t ...

  10. MyBatis学习(三)

    前言 感觉学习进度还是比较慢啊,一整天的学习效率不是很高,一会看电视,一会喝茶,对自己的要求不严格...今天就说说关联表数据的插入以及别名的使用. 正文 1.关联插入 之前,我在数据库中已经创建了一张 ...