Python测试框架nose之设计case(2)

官方链接:

test tools

1.nose 框架同unittest一样支持包,模块,类级别的setUp和tearDown

所有在test模块下的函数,凡是符合正则testMatch条件((?:^|[\\b_\\.-])[Tt]est都封装入FunctionTestCase

test functions支持函数级别的setUp

例:

def setup_func():
    "set up test fixtures"

def teardown_func():
    "tear down test fixtures"

@with_setup(setup_func, teardown_func)
def test():
    "test ..."

2.nose.tools的使用

nose.tools. ok_ ( expr, msg=None )

Shorthand for assert. Saves 3 whole characters!

nose.tools. eq_ ( a, b, msg=None )

Shorthand for ‘assert a == b, “%r != %r” % (a, b)

nose.tools. make_decorator ( func )

Wraps a test decorator so as to properly replicate metadataof the decorated function, including nose’s additional stuff(namely, setup and teardown).

nose.tools. raises ( *exceptions )

Test must raise one of expected exceptions to pass.

@raises(TypeError, ValueError)
def test_raises_type_error():
    raise TypeError("This test passes")

@raises(Exception)
def test_that_fails_by_passing():
    pass
nose.tools. set_trace ( )

Call pdb.set_trace in the calling frame, first restoringsys.stdout to the real output stream. Note that sys.stdout is NOTreset to whatever it was before the call once pdb is done!

nose.tools. timed ( limit )

Test must finish within specified time limit to pass.

Example use:

@timed(.1)
def test_that_fails():
    time.sleep(.2)
nose.tools. with_setup ( setup=None, teardown=None )

Decorator to add setup and/or teardown methods to a test function:

@with_setup(setup, teardown)
def test_something():
    " ... "

Note that with_setup is useful only for test functions, not for testmethods or inside of TestCase subclasses.

nose.tools. istest ( func )

Decorator to mark a function or method as a test

nose.tools. nottest ( func )

Decorator to mark a function or method as not a test





  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值