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 Boot(一)
(一)如何使用IDEA新建一个Spring Boot项目 https://www.cnblogs.com/wmyskxz/p/9010832.html
- IDEA配合Flash CS6开发Flash项目--配置篇
前端篇: 1:下载好IDEA和Flash CS6 2:配置IDEA 打开IDEA,点击创建新项目,选择Flash项目. 一开始没有装Flex SDK的界面会显示红色的none字样,这时需要找到自己下载 ...
- DocumentBuilderFactory.newInstance() 异常解决
现象: objc[27212]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk ...
- Webpack学习-工作原理(上)
对于webpack的认识始终停留在对脚手架的使用,不得不说脚手架既方便又好用,修改起来也方便,只需要知道webpack中各个配置项的功能,于是对于我们来说,webpack始终就是一个黑盒子,我们完全不 ...
- java根据输入的字符串和字节数来截取,输出对应字节数的字符串
public class Test { //要进行截取操作的字符串 static String ss; //截取的字符串的字节数 static int n; public static void ma ...
- oracle 字符串 正则表达式 拆分,排序,合并
需求,表数据如:要求圈中的数据,必须根据线芯有序排列. 思路: 1.首先根据分号分隔元素.oracle 很蛋疼,没有提供字符串分隔函数,网上倒是多觉得有点麻烦,耐着性子继续网上找了下,还真让我找到一篇 ...
- [数]数学系列预习->补水题ver.
---恢复内容开始--- 话说要学反演了,contest一题都搞不定,整理题目暂且搁置,数学笨蛋来学一下数学_(:з」∠)_ ---恢复内容结束--- 是的,预习看了半天教学,没有整理,做题又都不会, ...
- 【基于微信小程序的社区电商平台】Alpha迭代心得
项目团队:小豆芽 开发周期:11.5-12.2(Alpha版本) 设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 解决问题:当前电商平台卖家买家角 ...
- spring boot hello world
本文讲解初始用户搭建spring boot 工程. 新建工程目录结构: application.java放在最外层的包目录里 先添加pom.xml的依赖包: <project xmlns=&qu ...
- logging日志——Basic Logging Tutorial
在logging.basicConfig()函数中可通过具体参数来更改logging模块默认行为,可用参数有: filename,filemode,datefmt,format,level,strea ...