We'll be using nose for testing purposes.
The basic premise is simple. Write a file that imports solely the modules you want to test.
Write one test for each type-support that you want to be able to check.
From this guide,
we have the following example of ensuring that a user-defined function multiply
operates the way it is intended to:
from unnecessary_math import multiply
def test_numbers_3_4():
assert multiply(3,4) == 12
def test_strings_a_3():
assert multiply('a',3) == 'aaa'
As you can see, the test makes sure that if a string is passed, the interpretation is to repeat the string, whereas integers get multiplied. While python is not a strongly-typed language, it is highly encouraged that you write tests for each type you wish your function to support. This way, when you make changes, the test ensures the consistent functionality of your code.
The syntax (assuming you have the nosetests library installed -- see here for instructions.
nosetests test_um_nose.py
will run the specific file. You can pass the -v
( --verbose
) flag as well for more information as the tests run.
... and that's about all you need to know to get started!
If you want to set up some environmental variables to test functions on, see
http://pythontesting.net/framework/nose/nose-introduction/
which is an excellent walk-through.