Skip to content
Snippets Groups Projects
Select Git revision
  • 42f0ec4d3df42225eaea431afed1dc577a5463d8
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

testutils.py

Blame
  • user avatar
    Tobias Schmidt authored
    adding the function RunTests to each python unittest allows that the
    test is executed either with the default TestRunner or an XMLTestRunner
    for producing an XML output file. With no command line argument, the
    default Runner is used (same behaviour as previously), with 'xml' as
    the first argument, the XMLTestRunner is used.
    63afd372
    History
    testutils.py 1.51 KiB
    def RunTests():
      '''
      This function behaves as a custom TestLoader for python unittests.
    
      With no system arguments, the default unittest TestRunner is used.
    
      If the first system argument (sys.argv[1]) is set to 'xml', a XMLTestRunner
      is used, which produces a JUnit compatible XML output file. Within the current
      module, each function is identified which is a subclass of unittest.TestCase
      and for each TestCase, a test suite is executed, producing an individual
      output file for each TestCase. The output file has the name,
      'PYTEST-<TestCaseName>.xml'.
    
      Example of a Python testcase:
    
      .. code-block:: python
    
        import unittest
    
        class TestRenumber(unittest.TestCase):
    
          def setUp(self):
            # prepare stuff"
            pass
    
          def testSomeFunction(self):
            # do some asserts
            pass
    
        if __name__ == "__main__":
          from ost import testutils
          testutils.RunTests()
    
      '''
      import unittest
      import sys
      try:
        if len(sys.argv)>1 and sys.argv[1]=='xml':
          import inspect
          import types
          import __main__
          from ost import xmlrunner
          for name, obj in inspect.getmembers(__main__):
            if (isinstance(obj, (type, types.ClassType)) and
                                issubclass(obj, unittest.TestCase)):
              suite = unittest.TestLoader().loadTestsFromTestCase(obj)
              stream = open('PYTEST-%s.xml'%name, 'w')
              xmlrunner.XMLTestRunner(stream).run(suite)
              stream.close()
    
        else:
          unittest.main()
      except Exception, e:
        print e