pytest-subtests


Namepytest-subtests JSON
Version 0.14.1 PyPI version JSON
download
home_pagehttps://github.com/pytest-dev/pytest-subtests
Summaryunittest subTest() support and subtests fixture
upload_time2024-12-10 00:21:04
maintainerNone
docs_urlNone
authorBruno Oliveira
requires_python>=3.9
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`_.

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": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "test, unittest, pytest",
    "author": "Bruno Oliveira",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/c0/4c/ba9eab21a2250c2d46c06c0e3cd316850fde9a90da0ac8d0202f074c6817/pytest_subtests-0.14.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\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.14.1",
    "project_urls": {
        "Homepage": "https://github.com/pytest-dev/pytest-subtests"
    },
    "split_keywords": [
        "test",
        " unittest",
        " pytest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a9b77ca948d35642ae72500efda6ba6fa61dcb6683feb596d19c4747c63c0789",
                "md5": "3cb73cc387b62c153def710660681960",
                "sha256": "e92a780d98b43118c28a16044ad9b841727bd7cb6a417073b38fd2d7ccdf052d"
            },
            "downloads": -1,
            "filename": "pytest_subtests-0.14.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3cb73cc387b62c153def710660681960",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8833,
            "upload_time": "2024-12-10T00:20:58",
            "upload_time_iso_8601": "2024-12-10T00:20:58.873489Z",
            "url": "https://files.pythonhosted.org/packages/a9/b7/7ca948d35642ae72500efda6ba6fa61dcb6683feb596d19c4747c63c0789/pytest_subtests-0.14.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c04cba9eab21a2250c2d46c06c0e3cd316850fde9a90da0ac8d0202f074c6817",
                "md5": "f4dadd94661e81b47fdad3ddedc51038",
                "sha256": "350c00adc36c3aff676a66135c81aed9e2182e15f6c3ec8721366918bbbf7580"
            },
            "downloads": -1,
            "filename": "pytest_subtests-0.14.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f4dadd94661e81b47fdad3ddedc51038",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 17632,
            "upload_time": "2024-12-10T00:21:04",
            "upload_time_iso_8601": "2024-12-10T00:21:04.856012Z",
            "url": "https://files.pythonhosted.org/packages/c0/4c/ba9eab21a2250c2d46c06c0e3cd316850fde9a90da0ac8d0202f074c6817/pytest_subtests-0.14.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-10 00:21:04",
    "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.65637s