学习python单元测试框架nose之---05nose的tools使用

7 篇文章 0 订阅

nose.tools 提供一些方法可以方便我们写测试用例,让测试更简单

nose.tools.ok_(exprmsg=None)

Shorthand for assert. Saves 3 whole characters!

nose.tools. eq_ ( abmsg=None )

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

nose.tools. make_decorator ( func )

Wraps a test decorator so as to properly replicate metadata of 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.

Example use:

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

@raises(Exception)
def test_that_fails_by_passing():
    pass

If you want to test many assertions about exceptions in a single test, you may want to use assert_raises instead.

nose.tools. set_trace ( )

Call pdb.set_trace in the calling frame, first restoring sys.stdout to the real output stream. Note that sys.stdout is NOT reset 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=Noneteardown=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 test methods 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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值