Python Pre-testing for exceptions when coverage fails
Posted
by Tal Weiss
on Stack Overflow
See other posts from Stack Overflow
or by Tal Weiss
Published on 2010-04-15T18:00:30Z
Indexed on
2010/04/15
18:03 UTC
Read the original article
Hit count: 419
I recently came across a simple but nasty bug. I had a list and I wanted to find the smallest member in it. I used Python's built-in min(). Everything worked great until in some strange scenario the list was empty (due to strange user input I could not have anticipated). My application crashed with a ValueError (BTW - not documented in the official docs).
I have very extensive unit tests and I regularly check coverage to avoid surprises like this. I also use Pylint (everything is integrated in PyDev) and I never ignore warnings, yet I failed to catch this bug before my users did.
Is there anything I can change in my methodology to avoid these kind of runtime errors? (which would have been caught at compile time in Java / C#?).
I'm looking for something more than wrapping my code with a big try-except. What else can I do? How many other build in Python functions are hiding nasty surprises like this???
© Stack Overflow or respective owner