1:orphan: 2 3.. _features: 4 5pytest: helps you write better programs 6======================================= 7 8 9The ``pytest`` framework makes it easy to write small tests, yet 10scales to support complex functional testing for applications and libraries. 11 12An example of a simple test: 13 14.. code-block:: python 15 16 # content of test_sample.py 17 def inc(x): 18 return x + 1 19 20 21 def test_answer(): 22 assert inc(3) == 5 23 24 25To execute it: 26 27.. code-block:: pytest 28 29 $ pytest 30 =========================== test session starts ============================ 31 platform linux -- Python 3.x.y, pytest-4.x.y, py-1.x.y, pluggy-0.x.y 32 cachedir: $PYTHON_PREFIX/.pytest_cache 33 rootdir: $REGENDOC_TMPDIR 34 collected 1 item 35 36 test_sample.py F [100%] 37 38 ================================= FAILURES ================================= 39 _______________________________ test_answer ________________________________ 40 41 def test_answer(): 42 > assert inc(3) == 5 43 E assert 4 == 5 44 E + where 4 = inc(3) 45 46 test_sample.py:6: AssertionError 47 ========================= 1 failed in 0.12 seconds ========================= 48 49Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. 50See :ref:`Getting Started <getstarted>` for more examples. 51 52 53Features 54-------- 55 56- Detailed info on failing :ref:`assert statements <assert>` (no need to remember ``self.assert*`` names); 57 58- :ref:`Auto-discovery <test discovery>` of test modules and functions; 59 60- :ref:`Modular fixtures <fixture>` for managing small or parametrized long-lived test resources; 61 62- Can run :ref:`unittest <unittest>` (including trial) and :ref:`nose <noseintegration>` test suites out of the box; 63 64- Python 2.7, Python 3.4+, PyPy 2.3, Jython 2.5 (untested); 65 66- Rich plugin architecture, with over 315+ `external plugins <http://plugincompat.herokuapp.com>`_ and thriving community; 67 68 69Documentation 70------------- 71 72Please see :ref:`Contents <toc>` for full documentation, including installation, tutorials and PDF documents. 73 74 75Bugs/Requests 76------------- 77 78Please use the `GitHub issue tracker <https://github.com/pytest-dev/pytest/issues>`_ to submit bugs or request features. 79 80 81Changelog 82--------- 83 84Consult the :ref:`Changelog <changelog>` page for fixes and enhancements of each version. 85 86 87License 88------- 89 90Copyright Holger Krekel and others, 2004-2020. 91 92Distributed under the terms of the `MIT`_ license, pytest is free and open source software. 93 94.. _`MIT`: https://github.com/pytest-dev/pytest/blob/master/LICENSE 95