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 $ pytest 28 =========================== test session starts ============================ 29 platform linux -- Python 3.x.y, pytest-3.x.y, py-1.x.y, pluggy-0.x.y 30 rootdir: $REGENDOC_TMPDIR, inifile: 31 collected 1 item 32 33 test_sample.py F [100%] 34 35 ================================= FAILURES ================================= 36 _______________________________ test_answer ________________________________ 37 38 def test_answer(): 39 > assert inc(3) == 5 40 E assert 4 == 5 41 E + where 4 = inc(3) 42 43 test_sample.py:6: AssertionError 44 ========================= 1 failed in 0.12 seconds ========================= 45 46Due to ``pytest``'s detailed assertion introspection, only plain ``assert`` statements are used. 47See :ref:`Getting Started <getstarted>` for more examples. 48 49 50Features 51-------- 52 53- Detailed info on failing :ref:`assert statements <assert>` (no need to remember ``self.assert*`` names); 54 55- :ref:`Auto-discovery <test discovery>` of test modules and functions; 56 57- :ref:`Modular fixtures <fixture>` for managing small or parametrized long-lived test resources; 58 59- Can run :ref:`unittest <unittest>` (including trial) and :ref:`nose <noseintegration>` test suites out of the box; 60 61- Python 2.7, Python 3.4+, PyPy 2.3, Jython 2.5 (untested); 62 63- Rich plugin architecture, with over 315+ `external plugins <http://plugincompat.herokuapp.com>`_ and thriving community; 64 65 66Documentation 67------------- 68 69Please see :ref:`Contents <toc>` for full documentation, including installation, tutorials and PDF documents. 70 71 72Bugs/Requests 73------------- 74 75Please use the `GitHub issue tracker <https://github.com/pytest-dev/pytest/issues>`_ to submit bugs or request features. 76 77 78Changelog 79--------- 80 81Consult the :ref:`Changelog <changelog>` page for fixes and enhancements of each version. 82 83 84License 85------- 86 87Copyright Holger Krekel and others, 2004-2017. 88 89Distributed under the terms of the `MIT`_ license, pytest is free and open source software. 90 91.. _`MIT`: https://github.com/pytest-dev/pytest/blob/master/LICENSE 92