Testify Pythoinc的单元测试框架

简介: Testify 是Python的一款测试框架,可以替代unittest和nose。

image.png

特性

  • 类级别的配置,同一类的测试方法仅需运行一次配置。
  • 基于装饰器的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

相关文章
|
6月前
|
Web App开发 人工智能 JavaScript
主流自动化测试框架的技术解析与实战指南
本内容深入解析主流测试框架Playwright、Selenium与Cypress的核心架构与适用场景,对比其在SPA测试、CI/CD、跨浏览器兼容性等方面的表现。同时探讨Playwright在AI增强测试、录制回放、企业部署等领域的实战优势,以及Selenium在老旧系统和IE兼容性中的坚守场景。结合六大典型场景,提供技术选型决策指南,并展望AI赋能下的未来测试体系。
|
9月前
|
安全 Unix Linux
Metasploit Pro 4.22.7-2025050101 发布 - 专业渗透测试框架
Metasploit Pro 4.22.7-2025050101 发布 - 专业渗透测试框架
257 10
Metasploit Pro 4.22.7-2025050101 发布 - 专业渗透测试框架
|
4月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
253 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
4月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
359 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
10月前
|
安全 Ubuntu Linux
Metasploit Pro 4.22.7-2025042101 发布 - 专业渗透测试框架
Metasploit Pro 4.22.7-2025042101 (Linux, Windows) - 专业渗透测试框架
267 5
Metasploit Pro 4.22.7-2025042101 发布 - 专业渗透测试框架
|
5月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
395 2
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
|
5月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
464 1
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
|
5月前
|
安全 Linux 网络安全
Metasploit Framework 6.4.88 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.88 (macOS, Linux, Windows) - 开源渗透测试框架
608 0
|
5月前
|
缓存 安全 Linux
Metasploit Pro 4.22.8-2025082101 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025082101 (Linux, Windows) - 专业渗透测试框架
240 0
|
7月前
|
Web App开发 开发框架 .NET
Playwright 自动化测试系列(6)| 第三阶段:测试框架集成​指南:参数化测试 + 多浏览器并行执行
Pytest 与 Playwright 集成可提升自动化测试效率,支持参数化测试、多浏览器并行执行及统一报告生成。通过数据驱动、Fixture 管理和并行优化,显著增强测试覆盖率与执行速度,适用于复杂 Web 应用测试场景。