[Smtk-developers] New Python unit tests

David Thompson david.thompson at kitware.com
Thu Feb 19 21:43:46 EST 2015


Hi all,

I am switching to using the python unittest module for SMTK's python tests. One reason to do this is that test classes can be imported into interactive sessions and debugged.

As a side effect, there is now a new smtk submodule named smtk.testing that contains a function named process_arguments() and a variable named DATA_DIR, to handle fetching command-line arguments before the unittest framework sees them and complains. Use it like so:

    import smtk
    import smtk.testing
    from smtk.simple import *
    import unitttest, os

    class AnSMTKUnitTest(unittest.TestCase):
      def test(self):
        # do stuff like:
        model = Read(os.path.join(smtk.testing.DATA_DIR, 'foo.brep'))
        self.assertTrue(stuff, "Stuff was false")

    if __name__ == '__main__':
      smtk.testing.process_arguments()
      # Now sys.argv is empty and smtk.testing.DATA_DIR is set.
      unittest.main()

A full example is in smtk/model/testing/python/integrationMultiSessionDescriptivePhrase.py .

	David


More information about the Smtk-developers mailing list