Testify Pythoinc的单元测试框架

Testify 是Python的一款测试框架,能够替换unittestnose

《Testify Pythoinc的单元测试框架》

特征

  • 类级别的设置,统一类的测试要领仅需运转一次设置。
  • 基于装潢器的fixture要领,供应惰性求值属性和上下文治理。
  • 相似nose,能够深切包寻觅测试用例。
  • 能够以模块、类为单元运转测试,或许运转单个测试要领。
  • 支撑多线程测试。
  • 彩色输出。
  • 可扩大的插件体系。
  • 轻易的测试东西,包含turtle(用于mocking)、测试掩盖、机能剖析,等等。
  • 更加Pythonic的定名商定。

例子

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()

兼容Unittest

Testify能够直接运转unittests,不需修改任何代码:

testify my_unittests/foo_test.py

假如要运用Testify的高等特征,只需将unittest.TestCase改成testify.TestCase

项目主页

更多内容请接见Testify的GitHub页面

    原文作者:weakish
    原文地址: https://segmentfault.com/a/1190000000358572
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞