Writing tests

nose goes a step further when executing tests compared to unittest by running all classes and functions whose name matches the regular expression ((?:^|[b_.-])[Tt]est). It searches for test units in modules whose names match the same expression. Roughly, all callables that start with test and are located in a module that match that pattern will also be executed as a test.

For instance, this test_ok.py module will be recognized and run by nose:

$ cat test_ok.py
def test_ok():
    print('my test')

$ nosetests -v test_ok.test_ok ... ok ---------------------------------------------------------- Ran 1 test in 0.071s OK

Regular TestCase classes and doctests are executed as well.

Last but not least, nose provides assertion functions that are similar to the ones provided in the unittest.TestCase class methods. But these are provided as functions, with names that follow the PEP 8 naming conventions, rather than following the Java naming convention that unittest uses.