Write the test in a separate file, say test_mymod.py
:
import nose.tools as nt
import mymod
def test_double():
result = mymod.double(4)
nt.assert_equal(result, 8)
Running
Terminal> nosetests -s
makes the nose
tool run all test_*()
functions in all files
test*.py
in the current directory and in all subdirectories (recursevely)
with names tests
or *_tests
.
Start with test functions in the source code file. When the file contains many tests, or when you have many source code files, move tests to separate files.