Python unit testing super fun time
There's a weird thing that happens after a long night of mind-blowing back-breaking coding. Well, hacking in this case. Every time I stay up late working really hard on something, I feel compelled to blog/tweet/emote about my experience so others might feel sympathy/compassion for me. Even though I'm dizzyingly tired, and have to get up in ~5 hours, I cannot deny this urge to massage my ego. So tonight I bring to you the joy of unit testing in Python. I've been using py.test, and loving it. It extends the basic functionality of Python's built-in module, unittest (which is really not that bad). The main improvements are in the simplicity of writing the tests. Py.test supports unit testing on methods, classes, even whole modules. Here's your first test
def test_iszero():
assert 1==0def isEven(x):
assert x%2==0
def test_evenNumbers():
n = [1,2,3,4,5,6]
for x in n:
yield isEven,x