Revision 10fdd01d examples/test/runner.py

View differences:

examples/test/runner.py
1
import glob
1
#!/usr/bin/env python
2

  
3
"""
4
Run all mininet.examples tests
5
 -v : verbose output
6
 -quick : skip tests that take more than ~30 seconds
7
"""
8

  
2 9
import unittest
10
import os
11
import sys
12
from mininet.util import ensureRoot
13
from mininet.clean import cleanup
14

  
15
def runTests( testDir, verbosity=1 ):
16
    "discover and run all tests in testDir"
17
    # ensure root and cleanup before starting tests
18
    ensureRoot()
19
    cleanup()
20
    # discover all tests in testDir
21
    testSuite = unittest.defaultTestLoader.discover( testDir )
22
    # run tests
23
    unittest.TextTestRunner( verbosity=verbosity ).run( testSuite )
3 24

  
4
test_file_strings = glob.glob('test_*.py')
5
module_strings = [str[0:len(str)-3] for str in test_file_strings]
6
print module_strings
7
suites = [unittest.defaultTestLoader.loadTestsFromName(str) for str
8
          in module_strings]
9
testSuite = unittest.TestSuite(suites)
10
text_runner = unittest.TextTestRunner().run(testSuite)
25
if __name__ == '__main__':
26
    # get the directory containing example tests
27
    testDir = os.path.dirname( os.path.realpath( __file__ ) )
28
    verbosity = 2 if '-v' in sys.argv else 1
29
    runTests( testDir, verbosity )

Also available in: Unified diff