pytest-subtests


Namepytest-subtests JSON
Version 0.12.1 PyPI version JSON
download
home_pagehttps://github.com/pytest-dev/pytest-subtests
Summaryunittest subTest() support and subtests fixture
upload_time2024-03-07 22:53:16
maintainer
docs_urlNone
authorBruno Oliveira
requires_python>=3.7
licenseMIT
keywords test unittest pytest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ===============
pytest-subtests
===============

unittest ``subTest()`` support and ``subtests`` fixture.

.. image:: https://img.shields.io/pypi/v/pytest-subtests.svg
    :target: https://pypi.org/project/pytest-subtests
    :alt: PyPI version

.. image:: https://img.shields.io/conda/vn/conda-forge/pytest-subtests.svg
    :target: https://anaconda.org/conda-forge/pytest-subtests

.. image:: https://img.shields.io/pypi/pyversions/pytest-subtests.svg
    :target: https://pypi.org/project/pytest-subtests
    :alt: Python versions

.. image:: https://github.com/pytest-dev/pytest-subtests/workflows/test/badge.svg
  :target: https://github.com/pytest-dev/pytest-subtests/actions

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/ambv/black

----

This `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `cookiecutter-pytest-plugin`_ template.


Features
--------

* Adds support for `TestCase.subTest <https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests>`__.

* New ``subtests`` fixture, providing similar functionality for pure pytest tests.


Installation
------------

You can install ``pytest-subtests`` via `pip`_ from `PyPI`_::

    $ pip install pytest-subtests



Usage
-----

unittest subTest() example
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

    import unittest


    class T(unittest.TestCase):
        def test_foo(self):
            for i in range(5):
                with self.subTest("custom message", i=i):
                    self.assertEqual(i % 2, 0)


    if __name__ == "__main__":
        unittest.main()


**Output**

.. code-block::

    λ pytest .tmp\test-unit-subtest.py
    ======================== test session starts ========================
    ...
    collected 1 item

    .tmp\test-unit-subtest.py FF.                                  [100%]

    ============================= FAILURES ==============================
    _________________ T.test_foo [custom message] (i=1) _________________

    self = <test-unit-subtest.T testMethod=test_foo>

        def test_foo(self):
            for i in range(5):
                with self.subTest('custom message', i=i):
    >               self.assertEqual(i % 2, 0)
    E               AssertionError: 1 != 0

    .tmp\test-unit-subtest.py:9: AssertionError
    _________________ T.test_foo [custom message] (i=3) _________________

    self = <test-unit-subtest.T testMethod=test_foo>

        def test_foo(self):
            for i in range(5):
                with self.subTest('custom message', i=i):
    >               self.assertEqual(i % 2, 0)
    E               AssertionError: 1 != 0

    .tmp\test-unit-subtest.py:9: AssertionError
    ================ 2 failed, 1 passed in 0.07 seconds =================


``subtests`` fixture example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: python

    def test(subtests):
        for i in range(5):
            with subtests.test(msg="custom message", i=i):
                assert i % 2 == 0


**Output**

.. code-block::

    λ pytest .tmp\test-subtest.py
    ======================== test session starts ========================
    ...
    collected 1 item

    .tmp\test-subtest.py .F.F..                                    [100%]

    ============================= FAILURES ==============================
    ____________________ test [custom message] (i=1) ____________________

        def test(subtests):
            for i in range(5):
                with subtests.test(msg='custom message', i=i):
    >               assert i % 2 == 0
    E               assert (1 % 2) == 0

    .tmp\test-subtest.py:4: AssertionError
    ____________________ test [custom message] (i=3) ____________________

        def test(subtests):
            for i in range(5):
                with subtests.test(msg='custom message', i=i):
    >               assert i % 2 == 0
    E               assert (3 % 2) == 0

    .tmp\test-subtest.py:4: AssertionError
    ================ 2 failed, 1 passed in 0.07 seconds =================

Contributing
------------
Contributions are very welcome. Tests can be run with `tox`_:

.. code-block::

    tox -e py37

License
-------

Distributed under the terms of the `MIT`_ license, "pytest-subtests" is free and open source software


Issues
------

If you encounter any problems, please `file an issue`_ along with a detailed description.

.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter
.. _`@hackebrot`: https://github.com/hackebrot
.. _`MIT`: http://opensource.org/licenses/MIT
.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin
.. _`file an issue`: https://github.com/pytest-dev/pytest-subtests/issues
.. _`pytest`: https://github.com/pytest-dev/pytest
.. _`tox`: https://tox.readthedocs.io/en/latest/
.. _`pip`: https://pypi.org/project/pip/
.. _`PyPI`: https://pypi.org/project/pytest-subtests/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pytest-dev/pytest-subtests",
    "name": "pytest-subtests",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "test,unittest,pytest",
    "author": "Bruno Oliveira",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/5e/e1/07e3f31938c689dcf368fcb0e58d2285e6da158cc2dc2b419f18c4218303/pytest-subtests-0.12.1.tar.gz",
    "platform": null,
    "description": "===============\npytest-subtests\n===============\n\nunittest ``subTest()`` support and ``subtests`` fixture.\n\n.. image:: https://img.shields.io/pypi/v/pytest-subtests.svg\n    :target: https://pypi.org/project/pytest-subtests\n    :alt: PyPI version\n\n.. image:: https://img.shields.io/conda/vn/conda-forge/pytest-subtests.svg\n    :target: https://anaconda.org/conda-forge/pytest-subtests\n\n.. image:: https://img.shields.io/pypi/pyversions/pytest-subtests.svg\n    :target: https://pypi.org/project/pytest-subtests\n    :alt: Python versions\n\n.. image:: https://github.com/pytest-dev/pytest-subtests/workflows/test/badge.svg\n  :target: https://github.com/pytest-dev/pytest-subtests/actions\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/ambv/black\n\n----\n\nThis `pytest`_ plugin was generated with `Cookiecutter`_ along with `@hackebrot`_'s `cookiecutter-pytest-plugin`_ template.\n\n\nFeatures\n--------\n\n* Adds support for `TestCase.subTest <https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests>`__.\n\n* New ``subtests`` fixture, providing similar functionality for pure pytest tests.\n\n\nInstallation\n------------\n\nYou can install ``pytest-subtests`` via `pip`_ from `PyPI`_::\n\n    $ pip install pytest-subtests\n\n\n\nUsage\n-----\n\nunittest subTest() example\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    import unittest\n\n\n    class T(unittest.TestCase):\n        def test_foo(self):\n            for i in range(5):\n                with self.subTest(\"custom message\", i=i):\n                    self.assertEqual(i % 2, 0)\n\n\n    if __name__ == \"__main__\":\n        unittest.main()\n\n\n**Output**\n\n.. code-block::\n\n    \u03bb pytest .tmp\\test-unit-subtest.py\n    ======================== test session starts ========================\n    ...\n    collected 1 item\n\n    .tmp\\test-unit-subtest.py FF.                                  [100%]\n\n    ============================= FAILURES ==============================\n    _________________ T.test_foo [custom message] (i=1) _________________\n\n    self = <test-unit-subtest.T testMethod=test_foo>\n\n        def test_foo(self):\n            for i in range(5):\n                with self.subTest('custom message', i=i):\n    >               self.assertEqual(i % 2, 0)\n    E               AssertionError: 1 != 0\n\n    .tmp\\test-unit-subtest.py:9: AssertionError\n    _________________ T.test_foo [custom message] (i=3) _________________\n\n    self = <test-unit-subtest.T testMethod=test_foo>\n\n        def test_foo(self):\n            for i in range(5):\n                with self.subTest('custom message', i=i):\n    >               self.assertEqual(i % 2, 0)\n    E               AssertionError: 1 != 0\n\n    .tmp\\test-unit-subtest.py:9: AssertionError\n    ================ 2 failed, 1 passed in 0.07 seconds =================\n\n\n``subtests`` fixture example\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    def test(subtests):\n        for i in range(5):\n            with subtests.test(msg=\"custom message\", i=i):\n                assert i % 2 == 0\n\n\n**Output**\n\n.. code-block::\n\n    \u03bb pytest .tmp\\test-subtest.py\n    ======================== test session starts ========================\n    ...\n    collected 1 item\n\n    .tmp\\test-subtest.py .F.F..                                    [100%]\n\n    ============================= FAILURES ==============================\n    ____________________ test [custom message] (i=1) ____________________\n\n        def test(subtests):\n            for i in range(5):\n                with subtests.test(msg='custom message', i=i):\n    >               assert i % 2 == 0\n    E               assert (1 % 2) == 0\n\n    .tmp\\test-subtest.py:4: AssertionError\n    ____________________ test [custom message] (i=3) ____________________\n\n        def test(subtests):\n            for i in range(5):\n                with subtests.test(msg='custom message', i=i):\n    >               assert i % 2 == 0\n    E               assert (3 % 2) == 0\n\n    .tmp\\test-subtest.py:4: AssertionError\n    ================ 2 failed, 1 passed in 0.07 seconds =================\n\nContributing\n------------\nContributions are very welcome. Tests can be run with `tox`_:\n\n.. code-block::\n\n    tox -e py37\n\nLicense\n-------\n\nDistributed under the terms of the `MIT`_ license, \"pytest-subtests\" is free and open source software\n\n\nIssues\n------\n\nIf you encounter any problems, please `file an issue`_ along with a detailed description.\n\n.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter\n.. _`@hackebrot`: https://github.com/hackebrot\n.. _`MIT`: http://opensource.org/licenses/MIT\n.. _`cookiecutter-pytest-plugin`: https://github.com/pytest-dev/cookiecutter-pytest-plugin\n.. _`file an issue`: https://github.com/pytest-dev/pytest-subtests/issues\n.. _`pytest`: https://github.com/pytest-dev/pytest\n.. _`tox`: https://tox.readthedocs.io/en/latest/\n.. _`pip`: https://pypi.org/project/pip/\n.. _`PyPI`: https://pypi.org/project/pytest-subtests/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "unittest subTest() support and subtests fixture",
    "version": "0.12.1",
    "project_urls": {
        "Homepage": "https://github.com/pytest-dev/pytest-subtests"
    },
    "split_keywords": [
        "test",
        "unittest",
        "pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8a90afec13651a03a4c00bce27aa80ede29fbff469ea8021a71dfbcfbd48054",
                "md5": "e8a8060114853156bddb47d09e979163",
                "sha256": "100d9f7eb966fc98efba7026c802812ae327e8b5b37181fb260a2ea93226495c"
            },
            "downloads": -1,
            "filename": "pytest_subtests-0.12.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e8a8060114853156bddb47d09e979163",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7524,
            "upload_time": "2024-03-07T22:53:14",
            "upload_time_iso_8601": "2024-03-07T22:53:14.916865Z",
            "url": "https://files.pythonhosted.org/packages/a8/a9/0afec13651a03a4c00bce27aa80ede29fbff469ea8021a71dfbcfbd48054/pytest_subtests-0.12.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ee107e3f31938c689dcf368fcb0e58d2285e6da158cc2dc2b419f18c4218303",
                "md5": "67c49da1b10826e8122674d04d98fdb5",
                "sha256": "d6605dcb88647e0b7c1889d027f8ef1c17d7a2c60927ebfdc09c7b0d8120476d"
            },
            "downloads": -1,
            "filename": "pytest-subtests-0.12.1.tar.gz",
            "has_sig": false,
            "md5_digest": "67c49da1b10826e8122674d04d98fdb5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 15303,
            "upload_time": "2024-03-07T22:53:16",
            "upload_time_iso_8601": "2024-03-07T22:53:16.576686Z",
            "url": "https://files.pythonhosted.org/packages/5e/e1/07e3f31938c689dcf368fcb0e58d2285e6da158cc2dc2b419f18c4218303/pytest-subtests-0.12.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-07 22:53:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pytest-dev",
    "github_project": "pytest-subtests",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-subtests"
}
        
Elapsed time: 0.26846s