For this post, I thought of checking some useful tools for Python programs. Python does not detected many errors typical compilers detect unless the statement is executed (since it interprets the code as it is executed). For example, only when running the following program

x = 5
blablabla

we obtain the following error

Traceback (most recent call last):
File "withError.py", line 2, in <module>
blablabla
NameError: name 'blablabla' is not defined

In this case it was easy to find the error, but sometimes errors depend on a condition being met:

x = 5
y = int(raw_input())
if (y == 42):
blablabla

Running this program with the input “10” nothing happens, but with the input 42, the program outputs that blablabla is not defined.

In the next post, we will combine unit testing and coverage to guarantee that all statements are at least executed once and prevent obvious errors.

Advertisements