Python asserts



I was doing some python tests recently I came to use python asserts again, np_asserts, python asserts and unittest framework. All very very useful, but I think the original assert is so clever and easy to use, we should apply them in everyday life.


  I was comparing the name of a bank (string) with the calculated value of a function that returns it.
   assert get_from_id_name_bank(‘004’) == ‘TD’
  Similar to the example in [1]

np library

Np is also so straightforward, just need to do import numpy as np and it’s done! Put the comparison, and done!

Comparing arrays for example:

    All the supported functions are here [2].


That’s a complete framework for testing and it’s very simple and has set_up, and tear_down. All in it.

    python -m unittest -v test_module

You can add some verbosity via v while doing the execution





[3] (for python 3)



Leave a Reply

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

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

Facebook photo

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

Connecting to %s