You are reading the documentation for version 2.3 of OpenStructure. You may also want to read the documentation for: 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.7.1 1.8 1.9 1.10 1.11 2.0 2.1 2.2 2.3.1 devel

testutils – Utils for Running Python Unittests


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:

import unittest

class TestRenumber(unittest.TestCase):

  def setUp(self):
    # prepare stuff"

  def testSomeFunction(self):
    # do some asserts

if __name__ == "__main__":
  from ost import testutils

This function tries to ensure that a default compound library is set. When calling scripts with ost this is not needed, but since unit tests are called with python we need to ensure that it is set. The function is only expected to succeed (and return True) if COMPOUND_LIB was set when configuring the compilation.

It tries the following:

  • get it with ost.conop.GetDefaultLib()
  • look for compounds.chemlib in $OST_ROOT/share/openstructure
  • if OST_ROOT not set in the above, try to guess it based on the path of the conop module

To use this check modify the RunTests() call to read:

if __name__ == "__main__":
  from ost import testutils
  if testutils.SetDefaultCompoundLib():
    print 'No compound library available. Ignoring tests.'
Returns:True, if a compound library was found and set to be accessed with ost.conop.GetDefaultLib(). False otherwise.



Enter search terms or a module, class or function name.

Previous topic

ost.settings - Locate Files and Retrieve Preferences

Next topic

geom – vectors, matrices and geometrical objects

You are here