| 1 |
.. _features: |
| 2 |
|
| 3 |
.. sidebar:: **Next Open Trainings and Events** |
| 4 |
|
| 5 |
- `pytest development sprint <https://github.com/pytest-dev/sprint>`_, **July 20th -- 24th**, Klaus (AT), sign-up open until June 15th |
| 6 |
- `Professional Testing with Python <https://python-academy.com/courses/python_course_testing.html>`_, via `Python Academy <https://www.python-academy.com/>`_ (3 day in-depth training), **March 9th -- 11th 2027**, Leipzig (DE) / Remote |
| 7 |
|
| 8 |
Also see :doc:`previous talks and blogposts <talks>` |
| 9 |
|
| 10 |
pytest: helps you write better programs |
| 11 |
======================================= |
| 12 |
|
| 13 |
.. toctree:: |
| 14 |
:hidden: |
| 15 |
|
| 16 |
getting-started |
| 17 |
how-to/index |
| 18 |
reference/index |
| 19 |
explanation/index |
| 20 |
example/index |
| 21 |
|
| 22 |
.. toctree:: |
| 23 |
:caption: About the project |
| 24 |
:hidden: |
| 25 |
|
| 26 |
changelog |
| 27 |
contributing |
| 28 |
backwards-compatibility |
| 29 |
sponsor |
| 30 |
tidelift |
| 31 |
license |
| 32 |
contact |
| 33 |
|
| 34 |
.. toctree:: |
| 35 |
:caption: Useful links |
| 36 |
:hidden: |
| 37 |
|
| 38 |
pytest @ PyPI <https://pypi.org/project/pytest/> |
| 39 |
pytest @ GitHub <https://github.com/pytest-dev/pytest/> |
| 40 |
Issue Tracker <https://github.com/pytest-dev/pytest/issues> |
| 41 |
PDF Documentation <https://media.readthedocs.org/pdf/pytest/latest/pytest.pdf> |
| 42 |
|
| 43 |
.. module:: pytest |
| 44 |
|
| 45 |
The ``pytest`` framework makes it easy to write small, readable tests, and can |
| 46 |
scale to support complex functional testing for applications and libraries. |
| 47 |
|
| 48 |
|
| 49 |
**PyPI package name**: :pypi:`pytest` |
| 50 |
|
| 51 |
A quick example |
| 52 |
--------------- |
| 53 |
|
| 54 |
.. code-block:: python |
| 55 |
|
| 56 |
# content of test_sample.py |
| 57 |
def inc(x): |
| 58 |
return x + 1 |
| 59 |
|
| 60 |
|
| 61 |
def test_answer(): |
| 62 |
assert inc(3) == 5 |
| 63 |
|
| 64 |
|
| 65 |
To execute it: |
| 66 |
|
| 67 |
.. code-block:: pytest |
| 68 |
|
| 69 |
$ pytest |
| 70 |
=========================== test session starts ============================ |
| 71 |
platform linux -- Python 3.x.y, pytest-9.x.y, pluggy-1.x.y |
| 72 |
rootdir: /home/sweet/project |
| 73 |
collected 1 item |
| 74 |
|
| 75 |
test_sample.py F [100%] |
| 76 |
|
| 77 |
================================= FAILURES ================================= |
| 78 |
_______________________________ test_answer ________________________________ |
| 79 |
|
| 80 |
def test_answer(): |
| 81 |
> assert inc(3) == 5 |
| 82 |
E assert 4 == 5 |
| 83 |
E + where 4 = inc(3) |
| 84 |
|
| 85 |
test_sample.py:6: AssertionError |
| 86 |
========================= short test summary info ========================== |
| 87 |
FAILED test_sample.py::test_answer - assert 4 == 5 |
| 88 |
============================ 1 failed in 0.12s ============================= |
| 89 |
|
| 90 |
Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. |
| 91 |
See :ref:`Get started <getstarted>` for a basic introduction to using pytest. |
| 92 |
|
| 93 |
|
| 94 |
Features |
| 95 |
-------- |
| 96 |
|
| 97 |
- Detailed info on failing :ref:`assert statements <assert>` (no need to remember ``self.assert*`` names) |
| 98 |
|
| 99 |
- :ref:`Auto-discovery <test discovery>` of test modules and functions |
| 100 |
|
| 101 |
- :ref:`Modular fixtures <fixture>` for managing small or parametrized long-lived test resources |
| 102 |
|
| 103 |
- Can run :ref:`unittest <unittest>` (including trial) test suites out of the box |
| 104 |
|
| 105 |
- Python 3.10+ or PyPy 3 |
| 106 |
|
| 107 |
- Rich plugin architecture, with over 1300+ :ref:`external plugins <plugin-list>` and thriving community |
| 108 |
|
| 109 |
|
| 110 |
Documentation |
| 111 |
------------- |
| 112 |
|
| 113 |
* :ref:`Get started <get-started>` - install pytest and grasp its basics in just twenty minutes |
| 114 |
* :ref:`How-to guides <how-to>` - step-by-step guides, covering a vast range of use-cases and needs |
| 115 |
* :ref:`Reference guides <reference>` - includes the complete pytest API reference, lists of plugins and more |
| 116 |
* :ref:`Explanation <explanation>` - background, discussion of key topics, answers to higher-level questions |
| 117 |
|
| 118 |
|
| 119 |
Bugs/Requests |
| 120 |
------------- |
| 121 |
|
| 122 |
Please use the `GitHub issue tracker <https://github.com/pytest-dev/pytest/issues>`_ to submit bugs or request features. |
| 123 |
|
| 124 |
|
| 125 |
Support pytest |
| 126 |
-------------- |
| 127 |
|
| 128 |
`Open Collective`_ is an online funding platform for open and transparent communities. |
| 129 |
It provides tools to raise money and share your finances in full transparency. |
| 130 |
|
| 131 |
It is the platform of choice for individuals and companies that want to make one-time or |
| 132 |
monthly donations directly to the project. |
| 133 |
|
| 134 |
See more details in the `pytest collective`_. |
| 135 |
|
| 136 |
.. _Open Collective: https://opencollective.com |
| 137 |
.. _pytest collective: https://opencollective.com/pytest |
| 138 |
|
| 139 |
|
| 140 |
pytest for enterprise |
| 141 |
--------------------- |
| 142 |
|
| 143 |
Available as part of the Tidelift Subscription. |
| 144 |
|
| 145 |
The maintainers of pytest and thousands of other packages are working with Tidelift to deliver commercial support and |
| 146 |
maintenance for the open source dependencies you use to build your applications. |
| 147 |
Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. |
| 148 |
|
| 149 |
`Learn more. <https://tidelift.com/subscription/pkg/pypi-pytest?utm_source=pypi-pytest&utm_medium=referral&utm_campaign=enterprise&utm_term=repo>`_ |
| 150 |
|
| 151 |
Security |
| 152 |
~~~~~~~~ |
| 153 |
|
| 154 |
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>`__. |