pytest

pytest: simple powerful testing with Python

192 个版本 Python >=3.10
Brianna Laugher, Bruno Oliveira, Floris Bruynooghe, Freya Bruhin, Holger Krekel, Others (See AUTHORS), Ronny Pfannschmidt
安装
pip install pytest
poetry add pytest
pipenv install pytest
conda install pytest
描述

.. 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: Code coverage Status

.. 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 status

.. 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: Documentation Status

.. 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

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries.

An example of a simple test:

.. code-block:: python

# 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 <https://docs.pytest.org/en/stable/getting-started.html#our-first-test-run>_ for more examples.

Features

  • Detailed info on failing assert statements <https://docs.pytest.org/en/stable/how-to/assert.html>_ (no need to remember self.assert* names)

  • Auto-discovery <https://docs.pytest.org/en/stable/explanation/goodpractices.html#python-test-discovery>_ of test modules and functions

  • Modular fixtures <https://docs.pytest.org/en/stable/explanation/fixtures.html>_ for managing small or parametrized long-lived test resources

  • Can run unittest <https://docs.pytest.org/en/stable/how-to/unittest.html>_ (or trial) test suites out of the box

  • Python 3.10+ or PyPy3

  • Rich plugin architecture, with over 1300+ external plugins <https://docs.pytest.org/en/latest/reference/plugin_list.html>_ and thriving community

Documentation

For full documentation, including installation, tutorials and PDF documents, please see https://docs.pytest.org/en/stable/.

Bugs/Requests

Please use the GitHub issue tracker <https://github.com/pytest-dev/pytest/issues>_ to submit bugs or request features.

Changelog

Consult the Changelog <https://docs.pytest.org/en/stable/changelog.html>__ page for fixes and enhancements of each version.

Support 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: https://opencollective.com .. _pytest collective: https://opencollective.com/pytest

pytest for enterprise

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. <https://tidelift.com/subscription/pkg/pypi-pytest?utm_source=pypi-pytest&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>_

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 <https://github.com/pytest-dev/pytest/security/advisories/new>__.

License

Copyright Holger Krekel and others, 2004.

Distributed under the terms of the MIT_ license, pytest is free and open source software.

.. _MIT: https://github.com/pytest-dev/pytest/blob/main/LICENSE

版本列表
9.1.1 2026-06-19
9.1.0 2026-06-13
9.0.3 2026-04-07
9.0.2 2025-12-06
9.0.1 2025-11-12
9.0.0 2025-11-08
8.4.2 2025-09-04
8.4.1 2025-06-18
8.4.0 2025-06-02
8.3.5 2025-03-02
8.3.4 2024-12-01
8.3.3 2024-09-10
8.3.2 2024-07-25
8.3.1 2024-07-20
8.3.0 2024-07-20
8.2.2 2024-06-04
8.2.1 2024-05-19
8.2.0 2024-04-27
8.1.2 2024-04-26
8.1.1 2024-03-09
8.1.0 2024-03-03
8.0.2 2024-02-24
8.0.1 2024-02-16
8.0.0 2024-01-27
8.0.0rc2 2024-01-17
8.0.0rc1 2024-01-02
7.4.4 2023-12-31
7.4.3 2023-10-24
7.4.2 2023-09-07
7.4.1 2023-09-02
7.4.0 2023-06-23
7.3.2 2023-06-10
7.3.1 2023-04-14
7.3.0 2023-04-08
7.2.2 2023-03-03
7.2.1 2023-01-14
7.2.0 2022-10-25
7.1.3 2022-09-02
7.1.2 2022-04-23
7.1.1 2022-03-17
7.1.0 2022-03-13
7.0.1 2022-02-11
7.0.0 2022-02-04
7.0.0rc1 2021-12-07
6.2.5 2021-08-30
6.2.4 2021-05-04
6.2.3 2021-04-03
6.2.2 2021-01-25
6.2.1 2020-12-15
6.2.0 2020-12-12
6.1.2 2020-10-28
6.1.1 2020-10-03
6.1.0 2020-09-26
6.0.2 2020-09-11
6.0.1 2020-07-30
6.0.0 2020-07-28
6.0.0rc1 2020-07-10
5.4.3 2020-06-02
5.4.2 2020-05-08
5.4.1 2020-03-13
5.4.0 2020-03-12
5.3.5 2020-01-29
5.3.4 2020-01-20
5.3.3 2020-01-17
5.3.2 2019-12-14
5.3.1 2019-11-26
5.3.0 2019-11-19
5.2.4 2019-11-15
5.2.3 2019-11-14
5.2.2 2019-10-25
5.2.1 2019-10-06
5.2.0 2019-09-29
5.1.3 2019-09-21
5.1.2 2019-08-30
5.1.1 2019-08-20
5.1.0 2019-08-16
5.0.1 2019-07-05
5.0.0 2019-06-29
4.6.11 2020-06-05
4.6.10 2020-05-08
4.6.9 2020-01-04
4.6.8 2019-12-19
4.6.7 2019-12-06
4.6.6 2019-10-13
4.6.5 2019-08-05
4.6.4 2019-06-29
4.6.3 2019-06-11
4.6.2 2019-06-03
4.6.1 2019-06-02
4.6.0 2019-06-01
4.5.0 2019-05-11
4.4.2 2019-05-08
4.4.1 2019-04-15
4.4.0 2019-03-31
4.3.1 2019-03-12
4.3.0 2019-02-18
4.2.1 2019-02-13
4.2.0 2019-01-30
4.1.1 2019-01-12
4.1.0 2019-01-06
4.0.2 2018-12-14
4.0.1 2018-11-24
4.0.0 2018-11-14
3.10.1 2018-11-11
3.10.0 2018-11-04
3.9.3 2018-10-27
3.9.2 2018-10-23
3.9.1 2018-10-16
3.8.2 2018-10-02
3.8.1 2018-09-22
3.8.0 2018-09-06
3.7.4 2018-08-29
3.7.3 2018-08-26
3.7.2 2018-08-18
3.7.1 2018-08-02
3.7.0 2018-07-30
3.6.4 2018-07-28
3.6.3 2018-07-04
3.6.2 2018-06-20
3.6.1 2018-06-05
3.6.0 2018-05-23
3.5.1 2018-04-24
3.5.0 2018-03-22
3.4.2 2018-03-05
3.4.1 2018-02-20
3.4.0 2018-01-30
3.3.2 2018-01-04
3.3.1 2017-12-06
3.3.0 2017-11-27
3.2.5 2017-11-15
3.2.4 2017-11-14
3.2.3 2017-10-04
3.2.2 2017-09-07
3.2.1 2017-08-09
3.2.0 2017-08-01
3.1.3 2017-07-04
3.1.2 2017-06-09
3.1.1 2017-05-31
3.1.0 2017-05-22
3.0.7 2017-03-14
3.0.6 2017-01-22
3.0.5 2016-12-05
3.0.4 2016-11-11
3.0.3 2016-09-29
3.0.2 2016-09-02
3.0.1 2016-08-24
3.0.0 2016-08-19
2.9.2 2016-05-31
2.9.1 2016-03-18
2.9.0 2016-03-01
2.8.7 2016-01-24
2.8.6 2016-01-22
2.8.5 2015-12-12
2.8.4 2015-12-06
2.8.3 2015-11-19
2.8.2 2015-10-07
2.8.1 2015-09-29
2.8.0 2015-09-18
2.7.3 2015-09-15
2.7.2 2015-06-23
2.7.1 2015-05-19
2.7.0 2015-03-26
2.6.4 2014-10-24
2.6.3 2014-09-24
2.6.2 2014-09-05
2.6.1 2014-08-07
2.6.0 2014-07-20
2.5.2 2014-01-29
2.5.1 2013-12-17
2.5.0 2013-12-12
2.4.2 2013-10-04
2.4.1 2013-10-02
2.4.0 2013-10-01
2.3.5 2013-04-30
2.3.4 2012-11-20
2.3.3 2012-11-06
2.3.2 2012-10-25
2.3.1 2012-10-20
2.3.0 2012-10-19
2.2.4 2012-05-22
2.2.3 2012-02-06
2.2.2 2012-02-06
2.2.1 2011-12-16
2.2.0 2011-11-18
2.1.3 2011-10-18
2.1.2 2011-09-24
2.1.1 2011-08-20
2.1.0 2011-07-09
2.0.3 2011-04-17
2.0.2 2011-03-09
2.0.1 2011-02-07
2.0.0 2010-11-25