Skip to content

unittest

unittest docs

The internet seems to like pytest more than unittest

  • unittest is like Java

Django testing

  • Django uses unittest by default

Helper methods

What are the differences between setUpClass, setUpTestData and setUp in TestCase class? - Stack Overflow

setUpTestData

more performant than setUpClass

class Test(TestCase):
    @classmethod
    def setUpTestData(cls):
        pass

mock.patch

Expecting an Exception

self.assertRaises(ExceptionType, func, arg1, arg2)
self.assertRaises(ExceptionType, lambda: func(kwarg1="a", kwarg2="b"))

Last update: 2022-11-04