Pytest:帮助您编写更好的程序¶
这个 pytest
框架使编写小测试变得容易,但是可以扩展到支持应用程序和库的复杂功能测试。
简单测试示例:
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
执行:
$ pytest
=========================== test session starts ============================
platform linux -- Python 3.x.y, pytest-6.x.y, py-1.x.y, pluggy-0.x.y
cachedir: $PYTHON_PREFIX/.pytest_cache
rootdir: $REGENDOC_TMPDIR
collected 1 item
test_sample.py F [100%]
================================= FAILURES =================================
_______________________________ test_answer ________________________________
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)
test_sample.py:6: AssertionError
========================= short test summary info ==========================
FAILED test_sample.py::test_answer - assert 4 == 5
============================ 1 failed in 0.12s =============================
由于 pytest
详细的断言反省,只是简单的 assert
使用语句。见 Getting Started 更多示例。
特征¶
失败的详细信息 assert statements (不需要记住
self.assert*
姓名)Auto-discovery 测试模块和功能
Modular fixtures 用于管理小型或参数化的长期测试资源
Python 3.6+和PyPy 3
丰富的插件架构,超过315+ external plugins 繁荣的社区
错误/请求¶
请使用 GitHub issue tracker 提交错误或请求功能。
支持pytest¶
Open Collective 是一个开放和透明社区的在线融资平台。它提供了筹集资金和完全透明地分享财务的工具。
它是个人和公司选择的平台,希望直接向项目提供一次性或每月的捐款。
在中查看更多详细信息 pytest collective .
企业版pytest¶
作为Tidelift订阅的一部分提供。
pytest和其他数千个软件包的维护人员正在与Tidelift合作,为您用来构建应用程序的开源依赖项提供商业支持和维护。节省时间、降低风险并改善代码运行状况,同时向您所使用的确切依赖项的维护人员付费。
安全性¶
pytest从未与安全漏洞关联,但无论如何,要报告安全漏洞,请使用 Tidelift security contact . Tidelift将协调修复和披露。