# -*- 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. 在Java8的foreach()中不能break,如果需要continue时,可以使用return

    今天使用lambda表达式处理集合时,发现对return.break以及continue的使用有点迷惑,于是自己动手测试了一下,才发现在使用foreach()处理集合时不能使用break和contin ...

  2. 【WePY小程序框架实战四】-使用async&await异步请求数据

    [WePY小程序框架实战一]-创建项目 [WePY小程序框架实战二]-页面结构 [WePY小程序框架实战三]-组件传值 async await 是对promise的近一步优化,既解决了promise链 ...

  3. [转]ASP.NET 核心模块配置参考

    本文转自:https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore ...

  4. 设计模式学习总结(一)——设计原则与UML统一建模语言

    一.概要 设计模式(Design Pattern)是一套被反复使用.多数人知晓的.经过分类的.代码设计经验的总结. 使用设计模式的目的:为了代码可重用性.让代码更容易被他人理解.保证代码可靠性. 设计 ...

  5. HLOCAL 初探

    首先看一段程序,输出的结果为两个相同的整数(这两个整数是内存地址). #include "stdafx.h" #include <windows.h> int _tma ...

  6. [javaSE] 看博客学习多线程的创建方式和优劣比较和PHP多线程

    通过实现Runnable接口创建线程 获取Thread对象,new出来,构造函数参数:Runnable对象 Runnable是一个接口,定义一个类MyRunnable实现Runnable接口,实现ru ...

  7. CSS canvas 捕捉视频video元素截图

    video元素介绍: http://www.runoob.com/html/html5-video.html https://developer.mozilla.org/zh-CN/docs/Web/ ...

  8. JavaScript高级编程——Array数组迭代(every()、filter()、foreach()、map()、some(),归并(reduce() 和reduceRight() ))

    JavaScript高级编程——Array数组迭代(every().filter().foreach().map().some(),归并(reduce() 和reduceRight() )) < ...

  9. 2016计蒜之道复赛 百度地图的实时路况(Floyd 分治)

    题意 题目链接 Sol 首先一个结论:floyd算法的正确性与最外层\(k\)的顺序无关(只要保证是排列即可) 我大概想到一种证明方式就是把最短路树上的链拿出来,不论怎样枚举都会合并其中的两段,所以正 ...

  10. 【代码笔记】iOS-UIAlertView自动关闭

    一,效果图. 二,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UIVi ...