===============
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": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "test, unittest, pytest",
"author": "Bruno Oliveira",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/67/fe/e691d2f4ce061a475f488cad1ef58431556affea323dde5c764fd7515a70/pytest_subtests-0.13.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.13.1",
"project_urls": {
"Homepage": "https://github.com/pytest-dev/pytest-subtests"
},
"split_keywords": [
"test",
" unittest",
" pytest"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f5acfc132cb88e8f2042cebcb6ef0ffac40017c514fbadf3931e0b4bcb4bdfb6",
"md5": "9cd660cf972bba82f38a15c29c99d182",
"sha256": "ab616a22f64cd17c1aee65f18af94dbc30c444f8683de2b30895c3778265e3bd"
},
"downloads": -1,
"filename": "pytest_subtests-0.13.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9cd660cf972bba82f38a15c29c99d182",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 8038,
"upload_time": "2024-07-17T00:36:27",
"upload_time_iso_8601": "2024-07-17T00:36:27.663770Z",
"url": "https://files.pythonhosted.org/packages/f5/ac/fc132cb88e8f2042cebcb6ef0ffac40017c514fbadf3931e0b4bcb4bdfb6/pytest_subtests-0.13.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "67fee691d2f4ce061a475f488cad1ef58431556affea323dde5c764fd7515a70",
"md5": "bec625da98bc2663ac7588d1a4981a3c",
"sha256": "989e38f0f1c01bc7c6b2e04db7d9fd859db35d77c2c1a430c831a70cbf3fde2d"
},
"downloads": -1,
"filename": "pytest_subtests-0.13.1.tar.gz",
"has_sig": false,
"md5_digest": "bec625da98bc2663ac7588d1a4981a3c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 15936,
"upload_time": "2024-07-17T00:36:29",
"upload_time_iso_8601": "2024-07-17T00:36:29.359873Z",
"url": "https://files.pythonhosted.org/packages/67/fe/e691d2f4ce061a475f488cad1ef58431556affea323dde5c764fd7515a70/pytest_subtests-0.13.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-17 00:36:29",
"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"
}