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