From 37353a854e2545a9b1d8894660a6cf3a12294eba Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 4 Aug 2017 17:56:13 -0300 Subject: [PATCH] Implement suggestions by Raphael --- doc/en/unittest.rst | 53 +++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/doc/en/unittest.rst b/doc/en/unittest.rst index a2813333f..92b9e653e 100644 --- a/doc/en/unittest.rst +++ b/doc/en/unittest.rst @@ -5,14 +5,12 @@ unittest.TestCase Support ========================= -.. _`unittest.py style`: https://docs.python.org/3/library/unittest.html - -``pytest`` supports running Python `unittest.py style`_ tests out of the box. -It's meant for leveraging existing ``unittest``-style test suites +``pytest`` supports running Python ``unittest``-based tests out of the box. +It's meant for leveraging existing ``unittest``-based test suites to use pytest as a test runner and also allow to incrementally adapt -the test suite to take full advantage of pytest features. +the test suite to take full advantage of pytest's features. -To run an existing ``unittest``-style test suite using ``pytest``, simply type:: +To run an existing ``unittest``-style test suite using ``pytest``, type:: pytest tests @@ -20,16 +18,28 @@ To run an existing ``unittest``-style test suite using ``pytest``, simply type:: pytest will automatically collect ``unittest.TestCase`` subclasses and their ``test`` methods in ``test_*.py`` or ``*_test.py`` files. -Almost all ``unittest`` features are supported, like ``@unittest.skip`` style decorators, ``setUp/tearDown``, -``setUpClass/tearDownClass()``, etc (see :ref:`unittest-limitations`). +Almost all ``unittest`` features are supported: -Benefits --------- +* ``@unittest.skip`` style decorators; +* ``setUp/tearDown``; +* ``setUpClass/tearDownClass()``; -You can make use of several pytest features, most without changing any existing code: +.. _`load_tests protocol`: https://docs.python.org/3/library/unittest.html#load-tests-protocol +.. _`setUpModule/tearDownModule`: https://docs.python.org/3/library/unittest.html#setupmodule-and-teardownmodule +.. _`subtests`: https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests + +Up to this point pytest does not have support for the following features: + +* `load_tests protocol`_; +* `setUpModule/tearDownModule`_; +* `subtests`_; + +Benefits out of the box +----------------------- + +By running your test suite with pytest you can make use of several features, +in most cases without having to modify existing code: -* Use :ref:`plain assert-statements ` instead of ``self.assert*`` functions (`unittest2pytest - `__ is immensely helpful in this); * Obtain :ref:`more informative tracebacks `; * :ref:`stdout and stderr ` capturing; * :ref:`Test selection options ` using ``-k`` and ``-m`` flags; @@ -37,21 +47,8 @@ You can make use of several pytest features, most without changing any existing * :ref:`--pdb ` command-line option for debugging on test failures (see :ref:`note ` below); * Distribute tests to multiple CPUs using the `pytest-xdist `_ plugin; - -.. _unittest-limitations: - -Limitations ------------ - -.. _`load_tests protocol`: https://docs.python.org/3/library/unittest.html#load-tests-protocol -.. _`setUpModule/tearDownModule`: https://docs.python.org/3/library/unittest.html#setupmodule-and-teardownmodule -.. _`subtests`: https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests - -Pytest currently does not support the following ``unittest`` features: - -* `load_tests protocol`_; -* `setUpModule/tearDownModule`_; -* `subtests`_; +* Use :ref:`plain assert-statements ` instead of ``self.assert*`` functions (`unittest2pytest + `__ is immensely helpful in this); pytest features in ``unittest.TestCase`` subclasses