pytest-dev / pytest

pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. pytest 框架不仅能轻松编写小型测试,还能扩展以支持应用程序和库的复杂功能测试。

An example of a simple test: 一个简单的测试示例:

# content of test_sample.py
def inc(x):
    return x + 1

def test_answer():
    assert inc(3) == 5

To execute it: 执行方式:

$ pytest
============================= test session starts =============================
collected 1 items

test_sample.py F
================================== FAILURES ===================================
_________________________________ test_answer _________________________________

def test_answer():
>       assert inc(3) == 5
E       assert 4 == 5
E        +  where 4 = inc(3)

test_sample.py:5: AssertionError
========================== 1 failed in 0.04 seconds ===========================

Thanks to pytest’s detailed assertion introspection, you can simply use plain assert statements. See getting-started for more examples. 得益于 pytest 详细的断言自省(assertion introspection)功能,你只需使用普通的 assert 语句即可。更多示例请参阅入门指南(getting-started)。

Features

特性

  • Detailed info on failing assert statements (no need to remember self.assert* names)
  • 关于失败断言语句的详细信息(无需记忆 self.assert* 等方法名)
  • Auto-discovery of test modules and functions
  • 自动发现测试模块和函数
  • Modular fixtures for managing small or parametrized long-lived test resources
  • 用于管理小型或参数化长效测试资源的模块化 fixture
  • Can run unittest (or trial) test suites out of the box
  • 开箱即用,可运行 unittest(或 trial)测试套件
  • Python 3.10+ or PyPy3
  • 支持 Python 3.10+ 或 PyPy3
  • Rich plugin architecture, with over 1300+ external plugins and thriving community
  • 丰富的插件架构,拥有超过 1300 个外部插件和活跃的社区

Documentation

文档

For full documentation, including installation, tutorials and PDF documents, please see https://docs.pytest.org/en/stable/. 如需完整文档(包括安装、教程和 PDF 文档),请访问 https://docs.pytest.org/en/stable/。

Bugs/Requests

错误反馈/功能请求

Please use the GitHub issue tracker to submit bugs or request features. 请使用 GitHub issue 跟踪器提交错误或请求新功能。

Changelog

更新日志

Consult the Changelog page for fixes and enhancements of each version. 请查阅更新日志页面,了解每个版本的修复和改进。

Support pytest

支持 pytest

Open Collective is an online funding platform for open and transparent communities. It provides tools to raise money and share your finances in full transparency. It is the platform of choice for individuals and companies that want to make one-time or monthly donations directly to the project. See more details in the pytest collective. Open Collective 是一个为开放和透明社区提供支持的在线筹款平台。它提供了筹集资金并完全透明地共享财务状况的工具。对于希望直接向项目进行一次性或每月捐款的个人和公司来说,这是首选平台。更多详情请参阅 pytest collective。

pytest for enterprise

企业版 pytest

Available as part of the Tidelift Subscription. The maintainers of pytest and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more. 作为 Tidelift 订阅的一部分提供。pytest 及其他数千个软件包的维护者正与 Tidelift 合作,为您构建应用程序所使用的开源依赖项提供商业支持和维护。在节省时间、降低风险并改善代码质量的同时,直接资助您所使用依赖项的维护者。了解更多。

Security

安全性

If you have found an issue that you believe is a security vulnerability, please do not create an issue — instead, report it via a new security advisory. 如果您发现了一个认为是安全漏洞的问题,请不要创建 issue,而是通过新的安全公告(security advisory)进行报告。

License

许可证

Copyright Holger Krekel and others, 2004. Distributed under the terms of the MIT license, pytest is free and open source software. 版权所有 Holger Krekel 等人,2004。pytest 在 MIT 许可证条款下分发,是一款免费且开源的软件。