# -*- coding:utf-8 -*-
import unittest def runTest(testcaseclass,testcase=[]):
suite = unittest.TestSuite()
for case in testcase:
suite.addTest(testcaseclass(case))
unittest.TextTestRunner().run(suite) class test(unittest.TestCase): def setUp(self):
print 'This is the setup msg' def tearDown(self):
print 'This is the teardown msg'
@classmethod
def setUpClass(cls):
print 'this is the setupclass msg' @classmethod
def tearDownClass(cls):
print 'this is the teardownclass msg' def test1(self):
print 'This is the first testcase' def test2(self):
print 'This is the second testcase' def test3(self):
print 'This is the third testcase' runTest(test,['test2','test3','test1']) 输出如下:
C:\Python27\python.exe "E:/Project/A3A 8 4G/13.py"
... ---------------------------------------------------------------------- this is the setupclass msg
This is the setup msg
This is the second testcase This is the teardown msg This is the setup msg
This is the third testcase
This is the teardown msg
This is the setup msg
This is the first testcase
This is the teardown msg
this is the teardownclass msg Ran 3 tests in 0.000s OK Process finished with exit code 0

总结:

1、setup()和teardown()两个函数在每条测试用例执行时都会进行重复执行一次,该场景针对那些测试用例间有相互影响的场景,才需要在每执行一条新用例时进行一次初使化,执行完毕后再清空所有配置

2、setupclass(cls)和teardownclass(cls)两个函数在一个用例集合执行前只会执行一次,然后再所有用例执行完成后再清空所有配置,此种用法主要用在用例之间相互没有什么影响的场景

【Python】【unittest】unittest测试框架中setup,teardown与setupclass,teardownclass的区别的更多相关文章

  1. selenium中的setUp,tearDown与setUpClass,tearDownClass的区别

    def setUpClass(cls): cls.driver = webdriver.Chrome() cls.driver.maximize_window() def setUp(self): s ...

  2. Python的Django REST框架中的序列化及请求和返回

    Python的Django REST框架中的序列化及请求和返回 序列化Serialization 1. 设置一个新的环境 在我们开始之前, 我们首先使用virtualenv要创建一个新的虚拟环境,以使 ...

  3. selenium 测试框架中使用grid

    之前的测试框架:http://www.cnblogs.com/tobecrazy/p/4553444.html 配合Jenkins可持续集成:http://www.cnblogs.com/tobecr ...

  4. hibernate validate验证框架中@NotEmpty、@NotbBank、@NotNull的区别

    Hibernate Validator验证框架中@NotEmpty.@NotBlank.@NotNull 的区别 Hibernate Validator验证框架中@NotEmpty.@NotBlank ...

  5. python unittest自动测试框架

    编写函数或者类时进行测试,确保代码正常工作 python  unittest 模块提供了代码测试工具.按照定义测试包括两部分:管理测试依赖库的代码(称为‘固件’)和测试本身. 单元测试用于核实函数的某 ...

  6. Selenium 4 Python的最佳测试框架

    随着Python语言的使用越来越流行,基于Python的测试自动化框架也越来越流行.在项目选择最佳框架时,开发人员和测试人员会有些无法下手.做出选择是应该判断很多事情,框架的脚本质量,测试用例的简单性 ...

  7. Pytest单元测试框架之setup/teardown模块示例操作

    """模块级(setup_module/teardown_module)开始于模块始末,全局的函数级(setup_function/teardown_function)只 ...

  8. 在测试框架中使用Log4J 2

    之前的测试框架:http://www.cnblogs.com/tobecrazy/p/4553444.html 配合Jenkins可持续集成:http://www.cnblogs.com/tobecr ...

  9. Hibernate Validator验证框架中@NotEmpty、@NotBlank、@NotNull 的区别

    Hibernate Validator验证框架中@NotEmpty.@NotBlank.@NotNull的主要使用情况 @NotEmpty  用在集合类上面 @NotBlank   用在String上 ...

随机推荐

  1. UIKit 框架之UIResponder

    前面博客有讲触摸事件提过响应事件和响应者链,而管理响应者链的正是UIResponder. 一.代码 - (BOOL)application:(UIApplication *)application d ...

  2. 并发编程之 Exchanger 源码分析

    前言 JUC 包中除了 CountDownLatch, CyclicBarrier, Semaphore, 还有一个重要的工具,只不过相对而言使用的不多,什么呢? Exchange -- 交换器.用于 ...

  3. leetcode树专题894.897,919,951

    满二叉树是一类二叉树,其中每个结点恰好有 0 或 2 个子结点. 返回包含 N 个结点的所有可能满二叉树的列表. 答案的每个元素都是一个可能树的根结点. 答案中每个树的每个结点都必须有 node.va ...

  4. 码云创建maven工程

    码云创建maven工程步骤 1.现在码云上创建工程2.拉取到本地3.使用"touch .gitignore"命令创建.gitignore文件4.在文件中添加过滤文件: .setti ...

  5. 我是菜鸟,我怕谁(hdu2520)

    我是菜鸟,我怕谁 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  6. 【Winform系列】Winform控件DataGridView添加数据的几种方式

    1:直接添加 在控件中设置好每列的名称 例如: DataGridViewRow row = new DataGridViewRow(); int j = dgv.Rows.Add(row); dgv. ...

  7. Java开发中常用的设计模式(二)---单例模式

    一. 懒汉式单例 //懒汉式单例类.在第一次调用的时候实例化自己 public class Singleton { private Singleton() {} private static Sing ...

  8. VMware打开虚拟机没反应的解决方案(全面汇总)

    VMware打开虚拟机无反应的解决方案(全面汇总)虚拟机没反应的解决办法大概是如下几点:一.若是第一次安装后打不开虚拟机,大致是如下两种解决方案: 1.大多数时候,虚拟机打不开都是因为防火墙拦截所致 ...

  9. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  10. Angular Npm Package.Json文件详解

    Angular7 Npm Package.Json文件详解   近期时间比较充裕,正好想了解下Angular Project相关内容.于是将Npm官网上关于Package.json的官方说明文档进行了 ...