Skip to main content

evilunit

features

  • shortcuts

  • parameterized

  • nested

shortcuts

this is tiresome.

import unittest

class Tests(unittest.TestCase):
    def _getTarget(self):
        from foo.bar import boo
        return boo

    def _callFUT(self, *args, **kwargs):
        self._getTarget()(*args, **kwargs)

    def test_it(self):
        params = object()
        result = self._callFUT(params)
        self.assertEqual(result, params)

shortcuts decorator

  • test_target – adding _getTarget(), _makeOne() methods

  • test_function – adding _getTarget(), _callFUT() methods

import unittest
from evilunit import test_function

@test_function("foo.bar:boo")
class Tests(unittest.TestCase):
    def test_it(self):
        params = object()
        result = self._callFUT(params)
        self.assertEqual(result, params)

parameterized

import unittest
from evilunit import NestedTest, nested_test_compile

class Tests(unittest.TestCase):
    def _callFUT(self, x, y):
        return x + y

    @paramaterized([
        (1, 2, 3),
        (1, 1, 2),
        (1, 0, 1),
        (2, 3, 5),
        (4, 4, 8)
    ])
    def _test_add(self, x, y, expected):
        """adding number"""
        result = self._callFUT(x, y)
        self.assertEqual(result, expected)

    @classmethod
    def tearDownClass(cls):
        count_of_test_method = sum(1 for k, v in cls.__dict__.items() if k.startswith("test_") and callable(v))
        assert count_of_test_method == 5

nested

import unittest
from evilunit import NestedTest, nested_test_compile


L = []


@nested_test_compile
class ToplevelTest(NestedTest):
    @classmethod
    def setUpClass(cls):
        assert issubclass(cls, unittest.TestCase)
        L.append("t1")

    def setUp(self):
        assert isinstance(self, unittest.TestCase)
        L.append("t2")

    def test_it(self):
        assert isinstance(self, unittest.TestCase)
        L.append("t3")
        self.assertEqual(L, ["t1", "t2", "t3"])

    def tearDown(self):
        assert isinstance(self, unittest.TestCase)
        global L
        L = []

    class Child(NestedTest):
        @classmethod
        def setUpClass(cls):
            assert issubclass(cls, unittest.TestCase)
            L.append("m1")

        def setUp(self):
            assert isinstance(self, unittest.TestCase)
            L.append("m2")

        def test_it(self):
            assert isinstance(self, unittest.TestCase)
            L.append("m3")
            self.assertEqual(L, ["t1", "m1", "t2", "m2", "m3"])

        class GrandChild(NestedTest):
            @classmethod
            def setUpClass(cls):
                assert issubclass(cls, unittest.TestCase)
                L.append("n1")

            def setUp(self):
                assert isinstance(self, unittest.TestCase)
                L.append("n2")

            def test_it(self):
                assert isinstance(self, unittest.TestCase)
                L.append("n3")
                self.assertEqual(L, ["t1", "m1", "n1", "t2", "m2", "n2", "n3"])

    class Child2(NestedTest):
        @classmethod
        def setUpClass(cls):
            assert issubclass(cls, unittest.TestCase)
            L.append("o1")

        def setUp(self):
            assert isinstance(self, unittest.TestCase)
            L.append("o2")

        def test_it(self):
            assert isinstance(self, unittest.TestCase)
            L.append("o3")
            self.assertEqual(L, ["t1", "o1", "t2", "o2", "o3"])

0.1.1: - fix if fixture is undefined in child class parent class’s method is not called.

Metadata

Release files for evilunit 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for evilunit 0.2.1
File Interpreter ABI Platform Actions
evilunit-0.2.1-py3-none-any.whl Python 3 none any Details for evilunit-0.2.1-py3-none-any.whl

Release files / evilunit-0.2.1-py3-none-any.whl

Download URL evilunit-0.2.1-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61d1e2d29e7a119d87c100f221c05a2357b6db58c15b52a4f897528da1bbf0ec
BLAKE2b-256 checksum
How to use checksums
2a5138169e389f5860b4cf390c5f7f8823abc9fa2f1d1289eb1ea3504267c950
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.7.4

Security for evilunit 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page