3.14 unittest之skip
3.14 unittest之skip
前言
当测试用例写完后,有些模块有改动时候,会影响到部分用例的执行,这个时候我们希望暂时跳过这些用例。
或者前面某个功能运行失败了,后面的几个用例是依赖于这个功能的用例,如果第一步就失败了,后面的用例也就没必要去执行了,直接跳过就行,节省用例执行时间。
一、skip装饰器
skip装饰器一共有四个:
@unittest.skip(reason)
Unconditionally skip the decorated test. reason should describe why the test is being skipped.
翻译:无条件跳过用例,reason是说明原因。
@unittest.skipIf(condition, reason)
Skip the decorated test if condition is true.
翻译:condition为true的时候跳过。
@unittest.skipUnless(condition, reason)
Skip the decorated test unless condition is true.
翻译:condition为False的时候跳过。
@unittest.expectedFailure
Mark the test as an expected failure. If the test fails when run, the test is not counted as a failure.
翻译:断言的时候跳过。
二、skip案例

运行结果:
测试1
测试4
.ssx
----------------------------------------------------------------------
Ran 4 tests in 0.003s
OK (skipped=2, expected failures=1)
三、跳过整个测试类

四、参考代码:

# coding:utf-8
import unittest
class Test(unittest.TestCase):
@unittest.skip(u"无条件跳过此用例")
def test_1(self):
print "测试1"
@unittest.skipIf(True, u"为True的时候跳过")
def test_2(self):
print "测试2"
@unittest.skipUnless(False, u"为False的时候跳过")
def test_3(self):
print "测试3"
@unittest.expectedFailure
def test_4(self):
print "测试4"
self.assertEqual(2, 4, msg=u"判断相等")
if __name__ == "__main__":
unittest.main()

3.14 unittest之skip的更多相关文章
- python+selenium自动化软件测试(第3章):unittest
3.1 unittest简介 前言(python基础比较弱的,建议大家多花点时间把基础语法学好,这里有套视频,可以照着练习下:http://pan.baidu.com/s/1i44jZdb 密码:92 ...
- python+selenium自动化软件测试(第3章):unittes
From: https://blog.csdn.net/site008/article/details/77622472 3.1 unittest简介 前言 (python基础比较弱的,建议大家多花点 ...
- Selenium2+python自动化64-100(大结局)[已出书]
前言 小编曾经说过要写100篇关于selenium的博客文章,前面的64篇已经免费放到博客园供小伙伴们学习,后面的内容就不放出来了,高阶内容直接更新到百度阅读了. 一.百度阅读地址: 1.本书是在线阅 ...
- unittest学习4-跳过用例执行
unittest支持跳过单个测试方法,甚至整个测试用例,还支持将测试用例标记为“测试失败” 基本跳过如下: import unittestimport requests,sys class MyTes ...
- Apache RewriteRule
1.Rewirte主要的功能就是实现URL的跳转,它的正则表达式是基于Perl语言.可基 于服务器级的(httpd.conf)和目录级的 (.htaccess)两种方式.如果要想用到rewrite模块 ...
- Maven详细介绍
Maven 目录 1 什么是Maven? 2 Maven 的好处 3 获取和安装 3.1 获取 3.2 安装 3.2.1 环境变量的配置 4 设置本地仓库 5 创建简单的Maven实例 5.1 使用骨 ...
- Apache mod_rewrite规则重写的标志一览
1) R[=code](force redirect) 强制外部重定向 强制在替代字符串加上http://thishost[:thisport]/前缀重定向到外部的URL.如果code不指定,将用缺省 ...
- Java性能提示(全)
http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...
- 3Sum & 4Sum
3 Sum Given an array S of n integers, are there elements a, b, c in Ssuch that a + b + c = 0? Find a ...
随机推荐
- Spring Http Invoke 请求过程图
Spring Http Invoke 请求过程图:
- mlp_clf_mnist_test
import os os.environ['CUDA_VISIBLE_DEVICES'] = "0" from mlp_clf import MLPClassifier impor ...
- day 09初始函数
# with open('小护士班主任',encoding='utf-8') as f,open ('小护士班主任.bak','w',encoding='utf-8')as f2: # for lin ...
- 多个yml文件的读取方式
1配置pom.xml文件,以下配置将默认激活-dev.yml配置文件<profiles> <profile> <id>dev&l ...
- os.path官方文档(附翻译)
This module implements some useful functions on pathnames. To read or write files see open(), and fo ...
- Ubuntu开机启动roscore服务的设置
1.在/etc/init.d中添加启停脚本ros_daemon.bash: #!/bin/bash ### BEGIN INIT INFO # Provides: ros_daemon.bash # ...
- 三种Webpack打包方式
准备工作mkdir webpack_demo && cd webpack_demo #新建文件夹npm init #创建package.json文件npm install --save ...
- SQL Server数据库开发的二十一条军规
如果你正在负责一个基于SQL Server的项目,或者你刚刚接触SQL Server,你都有可能要面临一些数据库性能的问题,这篇文章会为你提供一些有用的指导(其中大多数也可以用于其它的DBMS).在这 ...
- Visual Studio+VAssistX自动添加注释,函数头注释,文件头注释
转载:http://blog.csdn.net/xzytl60937234/article/details/70455777 在VAssistX中为C++提供了比较规范注释模板,用这个注释模板为编写的 ...
- 搭建SSH框架心得
<Struts2+Spring4+hibernate3> 工程结构 导入相关jar包:自行网上百度即可,根据环境需要 写dao类 以及实现 package com.icommon.dao; ...