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的更多相关文章

  1. python+selenium自动化软件测试(第3章):unittest

    3.1 unittest简介 前言(python基础比较弱的,建议大家多花点时间把基础语法学好,这里有套视频,可以照着练习下:http://pan.baidu.com/s/1i44jZdb 密码:92 ...

  2. python+selenium自动化软件测试(第3章):unittes

    From: https://blog.csdn.net/site008/article/details/77622472 3.1 unittest简介 前言 (python基础比较弱的,建议大家多花点 ...

  3. Selenium2+python自动化64-100(大结局)[已出书]

    前言 小编曾经说过要写100篇关于selenium的博客文章,前面的64篇已经免费放到博客园供小伙伴们学习,后面的内容就不放出来了,高阶内容直接更新到百度阅读了. 一.百度阅读地址: 1.本书是在线阅 ...

  4. unittest学习4-跳过用例执行

    unittest支持跳过单个测试方法,甚至整个测试用例,还支持将测试用例标记为“测试失败” 基本跳过如下: import unittestimport requests,sys class MyTes ...

  5. Apache RewriteRule

    1.Rewirte主要的功能就是实现URL的跳转,它的正则表达式是基于Perl语言.可基 于服务器级的(httpd.conf)和目录级的 (.htaccess)两种方式.如果要想用到rewrite模块 ...

  6. Maven详细介绍

    Maven 目录 1 什么是Maven? 2 Maven 的好处 3 获取和安装 3.1 获取 3.2 安装 3.2.1 环境变量的配置 4 设置本地仓库 5 创建简单的Maven实例 5.1 使用骨 ...

  7. Apache mod_rewrite规则重写的标志一览

    1) R[=code](force redirect) 强制外部重定向 强制在替代字符串加上http://thishost[:thisport]/前缀重定向到外部的URL.如果code不指定,将用缺省 ...

  8. Java性能提示(全)

    http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.htmlComparing the performance of LinkedLi ...

  9. 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 ...

随机推荐

  1. Java程序设计第2次作业

  2. 将对象转成 json 以及 将字符串 hash(SHA1) 加密

    如下: /// <summary> /// 生成 Json /// </summary> /// <param name="obj"></ ...

  3. 遇到的有关iframe的滚动条问题

    今天才发现一个简单有趣的问题,有关iframe的: <div style="height: 800px;overflow: auto;"> <iframe src ...

  4. FastCGI 进程意外退出造成500错误

    在一台新服务器上,安装新网站,之前只放至了一个网站.是服务器商配置好的,非集成环境. 添加了一个新站,路径都制定好了,但是在访问时出现了500错误.提示貌似是php的问题,但是之前的网站,运行的是di ...

  5. lr_场景设计之组场景、nmon监控

    1.组场景常用于回归 ,可以设置成一个脚本后多久运行下一个脚本: Real-world Schedule和Basic schedule的区别:根据官方文档,这两种模式下,场景中的每个虚拟用户组(可看成 ...

  6. Phoenix安装

    第一步: 安装erlang虚拟机: 第二步: 安装Elixir Add Erlang Solutions repo: wget https://packages.erlang-solutions.co ...

  7. QT学习教程

    原地址:http://www.devbean.NET/2012/08/qt-study-road-2-catelog/ 网上看到的不错的教程 本教程以qt5为主,部分地方会涉及qt4.据说非常适合qt ...

  8. 终端的rz命令,覆盖原文件。

    不覆盖:rz 覆盖 同名文件:rz -y

  9. C#连接Access数据库

    OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=XX/XXX ...

  10. Spark在StandAlone模式下提交任务,spark.rpc.message.maxSize太小而出错

    1.错误信息org.apache.spark.SparkException: Job aborted due to stage failure:Serialized task 32:5 was 172 ...