Testing Quickstart

From Daya Bay
Jump to navigation Jump to search

Testing Quickstart

For instructions on how to write the tests themselves see the topic on Unit Tests. A list of relevant DocDB documents is available at oum:nose/intro/

nosetests basic usage

Search for tests using the default test finding approach in the current directory, with command :


For your tests to be found,

  • collect them in the tests folder of your project folder
  • name the python modules test_*.py
  • name the test functions test_*

See the examples of tests in

You can also run the tests from specific directories or modules with eg

nosetests tests/test_look.py

nosetests options

Nosetests has a large number of options, see them listed with :

nosetests --help    

Some of the most useful ones are :

-v / -vv / -vvv verbosity control, default is very terse just a "." for a successful test
-s / --no-capture stdout/stderr for failing tests is usually captured and output at the end of the test run, use this to output immediately

nose documentation

nosetests is the command line tool that exposes the functionality of the nose python package. Access the pydoc for the nose package with :

pydoc nose 

Or see it online at

Automated Build/Test Running

The results of automated testing are reported by the Bitten Trac plugin at

Some documentation on test triggering criteria are given on the above pages.

Adding a script to automated testing

Create the test

More instructions for this is available here.

  • Create a tests directory as sibling to the cmt directory of the project
  • Add a interface script at path tests/test_myscript.py
    • NB the directory must be called tests and the filename must be of form test_*.py

Example of tests/test_myscript.py :

from dybtest import Matcher, Run
  Example of interfacing : 
       "python share/myscript.py myarg1 myarg2"  
  into the automated testing system, without modifcation to the script.

  The script is run in a subprocess and the stdout/stderr is piped out and examined by the 
  matcher using python regular expressions that are matched against every line of output 
  providing line return codes when a match is found.
  The maximum return code from all the lines of output is the matcher return code, 
  which if greater than zero causes the test to fail

  If the running time of subprocess script exceeds the configured maxtime (in seconds), 
  the subprocess is killed.


checks = {
  '.*\*\*\* Break \*\*\* segmentation violation':3, 

m = Matcher( checks, verbose=False )
opts = { 'maxtime':300 }
def test_myscript():
   Run( "python share/myscript.py myarg1 myarg2"  , parser=m , opts=opts )().assert_() 

if __name__=='__main__':