pytest-dev/pytest

GitHub: pytest-dev/pytest

pytest 是一个成熟强大的 Python 测试框架,通过简洁的断言机制和模块化 fixture 让编写从小型单元测试到复杂功能测试都变得轻松高效。

Stars: 14208 | Forks: 3191

.. image:: https://github.com/pytest-dev/pytest/raw/main/doc/en/img/pytest_logo_curves.svg :target: https://docs.pytest.org/en/stable/ :align: center :height: 200 ## :alt: pytest .. image:: https://img.shields.io/pypi/v/pytest.svg :target: https://pypi.org/project/pytest/ .. image:: https://img.shields.io/conda/vn/conda-forge/pytest.svg :target: https://anaconda.org/conda-forge/pytest .. image:: https://img.shields.io/pypi/pyversions/pytest.svg :target: https://pypi.org/project/pytest/ .. image:: https://codecov.io/gh/pytest-dev/pytest/branch/main/graph/badge.svg :target: https://codecov.io/gh/pytest-dev/pytest :alt: 代码覆盖率状态 .. image:: https://github.com/pytest-dev/pytest/actions/workflows/test.yml/badge.svg :target: https://github.com/pytest-dev/pytest/actions?query=workflow%3Atest .. image:: https://results.pre-commit.ci/badge/github/pytest-dev/pytest/main.svg :target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest/main :alt: pre-commit.ci 状态 .. image:: https://www.codetriage.com/pytest-dev/pytest/badges/users.svg :target: https://www.codetriage.com/pytest-dev/pytest .. image:: https://readthedocs.org/projects/pytest/badge/?version=latest :target: https://pytest.readthedocs.io/en/latest/?badge=latest :alt: 文档状态 .. image:: https://img.shields.io/badge/Discord-pytest--dev-blue :target: https://discord.com/invite/pytest-dev :alt: Discord .. image:: https://img.shields.io/badge/Libera%20chat-%23pytest-orange :target: https://web.libera.chat/#pytest :alt: Libera chat ``pytest`` 框架让编写小型测试变得轻而易举,同时 也能扩展以支持应用程序和库的复杂功能测试。 一个简单测试的示例: .. code-block:: python ``` # test_sample.py 的内容 def inc(x): return x + 1 def test_answer(): assert inc(3) == 5 ``` 要执行它:: ``` $ 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 =========================== ``` 得益于 ``pytest`` 详细的断言内省机制,你可以直接使用普通的 ``assert`` 语句。查看 `入门指南 `_ 获取更多示例。 ## 功能 - 失败时提供 `assert 语句 `_ 的详细信息(无需记住 ``self.assert*`` 的名称) - `自动发现 `_ 测试模块和函数 - `模块化 fixture `_,用于 管理小型或参数化的长期测试资源 - 开箱即用地支持运行 `unittest `_(或 trial) 测试套件 - Python 3.10+ 或 PyPy3 - 丰富的插件架构,拥有 1300 多个 `外部插件 `_ 和活跃的社区 ## 文档 完整的文档,包括安装指南、教程和 PDF 文档,请访问 https://docs.pytest.org/en/stable/。 ## Bug/请求 请使用 `GitHub issue 跟踪器 `_ 提交 Bug 或功能请求。 ## 更新日志 请查阅 `更新日志 `__ 页面,了解每个版本的修复和增强。 ## 安全 如果您发现了一个您认为是安全漏洞的问题,请不要创建 issue——相反,请通过 `新的安全公告 `__ 来报告它。 ## 许可证 版权所有 Holger Krekel 及其他人,2004 年。 根据 `MIT`_ 许可证的条款分发,pytest 是自由且开源的软件。 .. _`MIT`: https://github.com/pytest-dev/pytest/blob/main/LICENSE
标签:Python, SOC Prime, 功能测试, 单元测试, 开发工具, 无后门, 测试框架, 逆向工具