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. 7天学完Java基础之4/7

    静态static 如果一个成员变量使用了static关键字,那么这个变量不再属于对象自己,而是属于所在的类,多个对象共享同一份数据 静态static 关键字修饰成员变量 public class St ...

  2. stylus基础教程,stylus实例教程,stylus语法总结

    stylus特点富于表现力.具有健壮性.功能丰富.动态编码不需要写CSS的冒号.分号.大括号和LESS.SASS功能类似,会这些的入手很快stylus特点安装使用stylus语法(一)选择器(二)变量 ...

  3. Caffe实战一(环境准备及CPU模式下编译)

    经过前几天的折腾,终于把Ubuntu16.04开发环境给搭建了起来,包括win10+Ubuntu双系统的安装.系统安装后的优化等等. 详见之前的文章:Ubuntu16.04.2 LTS 64bit系统 ...

  4. Codeforces Round #324 (Div. 2)

    CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...

  5. 转 Oracle最新PSU大搜罗

    Quick Reference to Patch Numbers for Database/GI PSU, SPU(CPU), Bundle Patches and Patchsets (文档 ID ...

  6. props.children 和容器类组件

    有一类组件,充当了容器的作用,它定义了一种外层结构形式,然后你可以往里面塞任意的内容.这种结构在实际当中非常常见,例如这种带卡片组件: 组件本身是一个不带任何内容的方形的容器,我可以在用这个组件的时候 ...

  7. 数字(number)

    数字(number) Time Limit:2000ms   Memory Limit:128MB 题目描述 LYK定义了一个新的计算. 具体地,一开始它有两个数字a和b. 每一步,它可以将b增加1, ...

  8. 【学习笔记】深入理解js原型和闭包(17)——补this

    本文对<深入理解js原型和闭包(10)——this>一篇进行补充,原文链接:https://www.cnblogs.com/lauzhishuai/p/10078307.html 原文中, ...

  9. iPhone4 offical AD

    iPhone4 is so much more than just a new products.I mean this would have a lot of impact on the way i ...

  10. 激活eclipse自动提示功能

    eclipse设置: Window->Preferences->Java->Editor->Content Assist