Few Things to Know in Unittest

I have completely shifted to pytest now, but it was standard unittest module that I started, like many others.

Pytest is simple, intuitive and easy to work with but it always have to be installed as an additional package, sometime installing new things is not possible. (like on rigid office installations :()

So for that unittest, the standard package is a good option..

Apart from the usual unittests things, I have found the followings useful for real world unit testing of apps.

Putting them here as a reference

    def test_gauss_lobatto_quadrature(self):

    def test_mc_orthogonality(self):

The following decorators and exception implement test skipping and expected failures:

Unconditionally skip the decorated test. reason should describe why the test is being skipped.

@unittest.skipIf(condition, reason)
Skip the decorated test if condition is true.

@unittest.skipUnless(condition, reason)¶
Skip the decorated test unless condition is true.

Mark the test as an expected failure. If the test fails it will be considered a success. If the test passes, it will be considered a failure.

What other things will you add to this list?

One thought on “Few Things to Know in Unittest

  1. Pingback: Two of the Most Important Reason for Testing are … | SukhbinderSingh.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s