Writing and running tests on NIPY code

Please write tests for all code submitted to the repository. The code will be used by many people, and will in due course be used in live analyses, so we need to make sure that we have the best possible defenses against bugs. It also helps us think about code interfaces, and gives examples of code use that can be useful for others using the code.

Running the tests

After you've checked out and installed the project, you should be able to run the tests. To run the basic set of tests, open a python or ipython shell and type:

import neuroimaging
neuroimaging.test()

To run all the tests including those which require a gui, are long running or require the data package, type:

neuroimaging.test(flags="all")

To run all test for a given package (say foo.bar):

neuroimaging.foo.bar.test(flags="all")

To include tests which require a gui, are long running or require the data package, use one or more of the following options:

neuroimaging.test(flags=["gui", "slow", "data"])

Writing tests

Python's unit testing framework (the unittest module) is used to implement project tests. We use the convention that each package contains a subpackage called tests which contains modules defining test cases (subclasses of unittest.TestCase) for that package. The neuroimaging.tests package contains an example test case called test_template.TemplateTest to get you started writing your tests. Please try to include working test cases for all functions and classes that you contribute. Often, writing tests for your code before the code is written helps to frame your thoughts about what the code should look like.

Coverage testing

To gain an idea of how much of the code is actually run by the tests coverage testing can be done. This can often show up corners of the code which are not on the main path of execution and may need to have explicit tests written to ensure they are working correctly.