pytest以类形式的测试用例
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以类形式的测试用例的更多相关文章
- pytest以函数形式的测试用例
from __future__ import print_function#pytest以函数形式形成测试用例def setup_module(module): print('\nsetup_modu ...
- pytest以函数形式形成测试用例
#coding=utf- from __future__ import print_function #开始执行该文件时,该函数执行 def setup_module(module): print(' ...
- javascript多态 - 类形式实现demo
/* *多态 * 对传入的参数做判断以实现多种调用方式 */ //类形式实现 function Add(){ function zero(){ return 10; } function one(nu ...
- pytest之将多个测试用例放在一个类中,生成唯一临时文件夹
将多个测试用例放在一个类中 简单来说就是将多个测试用例放到类中,通过pytest去管理,这和Testng很像.示例代码如下: """ 将多个测试用例放到一个类中执行 &q ...
- Pytest从测试类外为测试用例动态注入数据
今天Nelly问我Pytest能不能支持从TestClass类外传入参数?从类外批量传入各个test方法需要的参数.因为数据文件可能有很多情况,不方便依次匹配. 然而又必须用类对用例进行归类及复用,数 ...
- pytest 10 skip跳过测试用例
pytest.mark.skip可以标记无法在某些平台上运行的测试功能,或者你希望失败的测试功能 skip意味着只有在满足某些条件时才希望测试通过,否则pytest应该跳过运行测试.常见事例时非win ...
- pytest自动化6:pytest.mark.parametrize装饰器--测试用例参数化
前言:pytest.mark.parametrize装饰器可以实现测试用例参数化. parametrizing 1. 下面是一个简单是实例,检查一定的输入和期望输出测试功能的典型例子 2. 标记单 ...
- WebService:java配置类形式发布WebService接口及遇见的问题总结
配置WebService前需要以下依赖jar包 #版本只供参考,具体看项目 <dependency> <grouId>org.apache.cxf</grouId> ...
- python pytest测试框架介绍二
在介绍一中简单介绍了pytest的安装和简单使用,接下来我们就要实际了解pytest了 一.pytest的用例发现规则 pytest可以在不同的函数.包中发现用例,发现的规则如下 文件名以test_开 ...
随机推荐
- USACO Training3.2 01串 By cellur925
题目传送门 一句话题意:求长度为n的有m个1的大小为第k个的01串. 暑假我做的时候是真·大暴力,用二进制枚举,55分,成功T掉无数点. 正解:开始可以用计数类dp来“预处理”,状态和转移都比较好想. ...
- sybase修改默认字符集为cp936
原文地址:http://blog.sina.com.cn/s/blog_4d6854860100xn3f.html 报错信息:2402 error converting characters into ...
- the little schemer 笔记(5)
第五章 “Oh My Gawd”:It's Full of Stars (rember* a l)是什么,其中a是cup,l是((coffee) cup ((tea) cup) rember*发音为r ...
- python实现堆排序
理论知识: 二叉树:度不超过2的树(节点最多有两个叉) 满二叉树:一个二叉树,如果每一个层的节点数都达到最大值,则这个二叉树就是满二叉树. 完全二叉树:叶节点只能出现在最下层和次下层,并且最下面一层的 ...
- AtCoder Grand Contest 010 F - Tree Game
题目传送门:https://agc010.contest.atcoder.jp/tasks/agc010_f 题目大意: 给定一棵树,每个节点上有\(a_i\)个石子,某个节点上有一个棋子,两人轮流操 ...
- 153 Find Minimum in Rotated Sorted Array 旋转数组的最小值
假设一个按照升序排列的有序数组从某未知的位置旋转.(比如 0 1 2 4 5 6 7 可能变成 4 5 6 7 0 1 2).找到其中最小的元素.你可以假设数组中不存在重复的元素.详见:https:/ ...
- C语言精确微秒级的延时
//----------------------------------------------------------------------------- // Delay_us //------ ...
- HtmlUnit爬取Ajax动态生成的页面内容
HtmlUnit说白了就是一个浏览器,这个浏览器是用Java写的无界面的浏览器,正因为其没有界面,因此执行的速度还是可以滴. HtmlUnit提供了一系列的API,这些API可以干的功能比较多,如表单 ...
- Python打开目录下所有文件
用Python打开指定目录下所有文件,统计文件里特定的字段信息. 这里是先进入2017-02-25到2017-03-03目录,然后进入特定IP段目录下,最后打开文件进行统计 import os, gl ...
- sass+compass起步
前言:Sass is an extension of CSS that adds power and elegance to the basic language. It allows you to ...