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 ...
随机推荐
- SQL运行优化收藏
如何让你的SQL运行得更快(转贴) ---- 人们在使用SQL时往往会陷入一个误区,即太关注于所得的结果是否正确,而忽略了不同的实现方法之间可能存在的性能差异,这种性能差异在大型的或是复杂的数据库环境 ...
- 图融合之加载子图:Tensorflow.contrib.slim与tf.train.Saver之坑
import tensorflow as tf import tensorflow.contrib.slim as slim import rawpy import numpy as np impor ...
- JeasyUI,导出Excel
这个是客户端表格导出伪Excel文档. 不知道为啥,超过200条,不能导出,显示网络错误 $.extend($.fn.datagrid.methods, { //超过200条,不能导出,显示网络错误? ...
- react canvas圆环动态百分比
import React from 'react'; import Tools from '../../tools/index' export default class PercentageRing ...
- Python爬取qq空间说说
#coding:utf-8 #!/usr/bin/python3 from selenium import webdriver import time import re import importl ...
- Mybatis面试题
面试题示例 1.JDBC编程有哪些不足之处,MyBatis是如何解决这些问题的? 1)数据库链接创建.释放频繁造成系统资源浪费从而影响系统性能,如果使用数据库链接池可解决此问题. 解决:在SqlMap ...
- JDBCUtils——DBCP
需要导入的包: mysql-connector-java-5.1.37-bin.jar commons-dbcp-1.4.jar commons-pool-1.6.jar 需要添加/配置的配置文件: ...
- 电脑小白和ta的小白电脑——Git的使用
简单介绍Git的安装和基本指令,不要抱太大希望QAQ 看完这篇博客,最多学会如何向远程库上传和从远程库拉取项目,复杂功能要 做中学! (一)Git的安装 1.下载 (1)官网下载地址: https:/ ...
- xcode10关于clang -lstdc++.6.0.9报错问题
因为xcode10已经废弃了libstdc++.6.0.9这个库,所以只需要在你的工程中删除这个库,然后添加libc++这个库就可以了.别的没什么,如果xcode10报错mutable开头的,大部分是 ...
- Spring Cloud分布式微服务云架构
分布式.微服务.云架构 JAVA语言开发.跨平台.高性能.高可用.安全.服务化.模块化.組件化.驱动式开发模式 commonservice eurekaNetflix 云端服务发现,一个基于 REST ...