Testify 是Python的一款测试框架,可以替代unittest
和nose
。
from testify import *
class AdditionTestCase(TestCase):
@class_setup
def init_the_variable(self):
self.variable = 0
@setup
def increment_the_variable(self):
self.variable += 1
def test_the_variable(self):
assert_equal(self.variable, 1)
@suite(\'disabled\', reason=\'ticket #123, not equal to 2 places\')
def test_broken(self):
# raises \'AssertionError: 1 !~= 1.01\'
assert_almost_equal(1, 1.01, threshold=2)
@teardown
def decrement_the_variable(self):
self.variable -= 1
@class_teardown
def get_rid_of_the_variable(self):
self.variable = None
if __name__ == \"__main__\":
run()
Testify可以直接运行unittests
,不需改动任何代码:
testify my_unittests/foo_test.py
如果要使用Testify的高级特性,只需将unittest.TestCase
改为testify.TestCase
。
更多内容请访问Testify的GitHub页面。
上一篇:python的锁
下一篇:Python正则表达式(2)