Skip to main content

unittest subTest() support and subtests fixture

Project description

unittest subTest() support and subtests fixture.

PyPI version https://img.shields.io/conda/vn/conda-forge/pytest-subtests.svg Python versions https://github.com/pytest-dev/pytest-subtests/workflows/test/badge.svg https://img.shields.io/badge/code%20style-black-000000.svg

This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Features

  • Adds support for TestCase.subTest.

  • 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

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

λ 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

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

Output

λ 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_subtests-0.14.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_subtests-0.14.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest_subtests-0.14.0.tar.gz.

File metadata

  • Download URL: pytest_subtests-0.14.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for pytest_subtests-0.14.0.tar.gz
Algorithm Hash digest
SHA256 8849818a0a515e8052734888cd0f6701291fdbf77552664d9ac772a2f8cc8f0f
MD5 b69a036ee4755b5dc34f22b03ed9f675
BLAKE2b-256 8e398c0a9e34860798b8831945546bf2ee7846a4a2c301d9a4a868dc19b479ef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_subtests-0.14.0.tar.gz:

Publisher: deploy.yml on pytest-dev/pytest-subtests

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_subtests-0.14.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_subtests-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7343f2efd90026998d8fe50fe9798cf54c5f00e162584ba4ce8d7658d2c6ed3e
MD5 98b23dfe20b45d423d410d6237c6e0a4
BLAKE2b-256 08f739bfd95b0367a9ca2a04087ff631592a472d9cb7564cdb3e13a42d9ae6b1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_subtests-0.14.0-py3-none-any.whl:

Publisher: deploy.yml on pytest-dev/pytest-subtests

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page