Skip to main content

unittest subTest() support and subtests fixture

Project description

unittest subTest() support and subtests fixture.

PyPI version Python versions See Build Status on Travis CI See Build Status on Azure

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.

Requirements

  • Python >= 3.4.

  • pytest >= 4.4.

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:

tox -e py37,linting

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.2.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

pytest_subtests-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest-subtests-0.2.0.tar.gz.

File metadata

  • Download URL: pytest-subtests-0.2.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for pytest-subtests-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0e48038a83c23c7cf60cde5b2f7d8bd61572c0292a9ca6da1c83ccfc88de38fa
MD5 7ade8c0a1cd89fbb7e1da90ccf80a051
BLAKE2b-256 394e3981610ed656928d5eb182187d7d0fe1f533491b7312d8a865dde1817c70

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_subtests-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

File hashes

Hashes for pytest_subtests-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e760f3aa9b467a33ca5c55ece0f94ad2521e62898a88ad2e5b64a6a2286014cf
MD5 26c91df7cd2352d3d4e3bffd613dd286
BLAKE2b-256 e2723fe18be1bd0824f4fdeb70598ca42c428759630de59f08fefe9d21745f39

See more details on using hashes here.

Supported by

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