| 1 |
.. image:: https://github.com/pytest-dev/pytest/raw/main/doc/en/img/pytest_logo_curves.svg |
| 2 |
:target: https://docs.pytest.org/en/stable/ |
| 3 |
:align: center |
| 4 |
:height: 200 |
| 5 |
:alt: pytest |
| 6 |
|
| 7 |
|
| 8 |
------ |
| 9 |
|
| 10 |
.. image:: https://img.shields.io/pypi/v/pytest.svg |
| 11 |
:target: https://pypi.org/project/pytest/ |
| 12 |
|
| 13 |
.. image:: https://img.shields.io/conda/vn/conda-forge/pytest.svg |
| 14 |
:target: https://anaconda.org/conda-forge/pytest |
| 15 |
|
| 16 |
.. image:: https://img.shields.io/pypi/pyversions/pytest.svg |
| 17 |
:target: https://pypi.org/project/pytest/ |
| 18 |
|
| 19 |
.. image:: https://codecov.io/gh/pytest-dev/pytest/branch/main/graph/badge.svg |
| 20 |
:target: https://codecov.io/gh/pytest-dev/pytest |
| 21 |
:alt: Code coverage Status |
| 22 |
|
| 23 |
.. image:: https://github.com/pytest-dev/pytest/actions/workflows/test.yml/badge.svg |
| 24 |
:target: https://github.com/pytest-dev/pytest/actions?query=workflow%3Atest |
| 25 |
|
| 26 |
.. image:: https://results.pre-commit.ci/badge/github/pytest-dev/pytest/main.svg |
| 27 |
:target: https://results.pre-commit.ci/latest/github/pytest-dev/pytest/main |
| 28 |
:alt: pre-commit.ci status |
| 29 |
|
| 30 |
.. image:: https://www.codetriage.com/pytest-dev/pytest/badges/users.svg |
| 31 |
:target: https://www.codetriage.com/pytest-dev/pytest |
| 32 |
|
| 33 |
.. image:: https://readthedocs.org/projects/pytest/badge/?version=latest |
| 34 |
:target: https://pytest.readthedocs.io/en/latest/?badge=latest |
| 35 |
:alt: Documentation Status |
| 36 |
|
| 37 |
.. image:: https://img.shields.io/badge/Discord-pytest--dev-blue |
| 38 |
:target: https://discord.com/invite/pytest-dev |
| 39 |
:alt: Discord |
| 40 |
|
| 41 |
.. image:: https://img.shields.io/badge/Libera%20chat-%23pytest-orange |
| 42 |
:target: https://web.libera.chat/#pytest |
| 43 |
:alt: Libera chat |
| 44 |
|
| 45 |
|
| 46 |
The ``pytest`` framework makes it easy to write small tests, yet |
| 47 |
scales to support complex functional testing for applications and libraries. |
| 48 |
|
| 49 |
An example of a simple test: |
| 50 |
|
| 51 |
.. code-block:: python |
| 52 |
|
| 53 |
# content of test_sample.py |
| 54 |
def inc(x): |
| 55 |
return x + 1 |
| 56 |
|
| 57 |
|
| 58 |
def test_answer(): |
| 59 |
assert inc(3) == 5 |
| 60 |
|
| 61 |
|
| 62 |
To execute it:: |
| 63 |
|
| 64 |
$ pytest |
| 65 |
============================= test session starts ============================= |
| 66 |
collected 1 items |
| 67 |
|
| 68 |
test_sample.py F |
| 69 |
|
| 70 |
================================== FAILURES =================================== |
| 71 |
_________________________________ test_answer _________________________________ |
| 72 |
|
| 73 |
def test_answer(): |
| 74 |
> assert inc(3) == 5 |
| 75 |
E assert 4 == 5 |
| 76 |
E + where 4 = inc(3) |
| 77 |
|
| 78 |
test_sample.py:5: AssertionError |
| 79 |
========================== 1 failed in 0.04 seconds =========================== |
| 80 |
|
| 81 |
|
| 82 |
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. |
| 83 |
|
| 84 |
|
| 85 |
Features |
| 86 |
-------- |
| 87 |
|
| 88 |
- Detailed info on failing `assert statements <https://docs.pytest.org/en/stable/how-to/assert.html>`_ (no need to remember ``self.assert*`` names) |
| 89 |
|
| 90 |
- `Auto-discovery |
| 91 |
<https://docs.pytest.org/en/stable/explanation/goodpractices.html#python-test-discovery>`_ |
| 92 |
of test modules and functions |
| 93 |
|
| 94 |
- `Modular fixtures <https://docs.pytest.org/en/stable/explanation/fixtures.html>`_ for |
| 95 |
managing small or parametrized long-lived test resources |
| 96 |
|
| 97 |
- Can run `unittest <https://docs.pytest.org/en/stable/how-to/unittest.html>`_ (or trial) |
| 98 |
test suites out of the box |
| 99 |
|
| 100 |
- Python 3.10+ or PyPy3 |
| 101 |
|
| 102 |
- Rich plugin architecture, with over 1300+ `external plugins <https://docs.pytest.org/en/latest/reference/plugin_list.html>`_ and thriving community |
| 103 |
|
| 104 |
|
| 105 |
Documentation |
| 106 |
------------- |
| 107 |
|
| 108 |
For full documentation, including installation, tutorials and PDF documents, please see https://docs.pytest.org/en/stable/. |
| 109 |
|
| 110 |
|
| 111 |
Bugs/Requests |
| 112 |
------------- |
| 113 |
|
| 114 |
Please use the `GitHub issue tracker <https://github.com/pytest-dev/pytest/issues>`_ to submit bugs or request features. |
| 115 |
|
| 116 |
|
| 117 |
Changelog |
| 118 |
--------- |
| 119 |
|
| 120 |
Consult the `Changelog <https://docs.pytest.org/en/stable/changelog.html>`__ page for fixes and enhancements of each version. |
| 121 |
|
| 122 |
|
| 123 |
Support pytest |
| 124 |
-------------- |
| 125 |
|
| 126 |
`Open Collective`_ is an online funding platform for open and transparent communities. |
| 127 |
It provides tools to raise money and share your finances in full transparency. |
| 128 |
|
| 129 |
It is the platform of choice for individuals and companies that want to make one-time or |
| 130 |
monthly donations directly to the project. |
| 131 |
|
| 132 |
See more details in the `pytest collective`_. |
| 133 |
|
| 134 |
.. _Open Collective: https://opencollective.com |
| 135 |
.. _pytest collective: https://opencollective.com/pytest |
| 136 |
|
| 137 |
|
| 138 |
pytest for enterprise |
| 139 |
--------------------- |
| 140 |
|
| 141 |
Available as part of the Tidelift Subscription. |
| 142 |
|
| 143 |
The maintainers of pytest and thousands of other packages are working with Tidelift to deliver commercial support and |
| 144 |
maintenance for the open source dependencies you use to build your applications. |
| 145 |
Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. |
| 146 |
|
| 147 |
`Learn more. <https://tidelift.com/subscription/pkg/pypi-pytest?utm_source=pypi-pytest&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_ |
| 148 |
|
| 149 |
Security |
| 150 |
^^^^^^^^ |
| 151 |
|
| 152 |
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>`__. |
| 153 |
|
| 154 |
|
| 155 |
License |
| 156 |
------- |
| 157 |
|
| 158 |
Copyright Holger Krekel and others, 2004. |
| 159 |
|
| 160 |
Distributed under the terms of the `MIT`_ license, pytest is free and open source software. |
| 161 |
|
| 162 |
.. _`MIT`: https://github.com/pytest-dev/pytest/blob/main/LICENSE |