Community

Zenoss Newsletter
Monitored by Zenoss
SourceForge.net Logo

TestGen4Web-Python: zopectl Integration

by zenoss last modified 2007-06-08 09:47

Zope 2.9.x and Higher

Zope 2.9 uses the zope.testing.testrunner package, whereas previous versions of Zope have all the code defined in bin/test.py. Due to this change and the fact that we have not finished porting Zenoss to Zope 2.9.x, we don't have examples of usage yet. However, the exmaple below should work without issue, the only difference being zopectl usage:

zopectl test -m ZenUITests

or

zopectl test -m ZenUITests.tests.testBrowserRecordings

Zope 2.8.x and Lower

In order for zopectl to be able to run tests, you need to have a test_suite() function defined that returns an instance of unittest.TestSuite. Here is an example:

import unittest
from glob import glob

from testgen.mechunit import MechanizeUnitTest

from Products import ZenUITests

def test_suite():
basePath = ZenUITests.__path__[0]
suites = []
for filename in glob('%s/tests/TestGen4Web/*.xml' % basePath):
loader = unittest.TestLoader()
test = MechanizeUnitTest
test.sourceFilename = filename
suite = loader.loadTestsFromTestCase(test)
suite = unittest.TestSuite(suite)
suites.append(suite)
return unittest.TestSuite(suites)

With this saved in the following Product path:

ZenUITests/tests/testBrowserRecordings.py

You may now run the following command from the Products directory:

zopectl test --libdir ZenUITests

or

zopectl test --libdir ZenUITests testBrowserRecordings

Supporting both zopectl and python Execution

Due to the import of the Zenoss product above, that example will not work if you want to run it solely from python. However, making the following adjustments will provide that ability:

import unittest
from glob import glob

from testgen.mechunit import MechanizeUnitTest

def convertFilesToSuite(filenames):
suites = []
for filename in filenames:
loader = unittest.TestLoader()
test = MechanizeUnitTest
test.sourceFilename = filename
suite = loader.loadTestsFromTestCase(test)
suite = unittest.TestSuite([suite])
suites.append(suite)
return unittest.TestSuite(suites)

def test_suite():
from Products import ZenUITests
basePath = ZenUITests.__path__[0]
filenames = glob('%s/tests/TestGen4Web/test*.xml' % basePath)
return convertFilesToSuite(filenames)

def nonZopeSuite():
filenames = glob('tests/TestGen4Web/test*.xml')
filenames += glob('TestGen4Web/test*.xml')
return convertFilesToSuite(filenames)

if __name__ == '__main__':
unittest.TextTestRunner().run(nonZopeSuite())

You may now use this as above with zopectl as well as the following:

cd $ZENHOME/Products/ZenUITests
python tests/testBrowserRecordings.py
cd tests
python testBrowserRecordings.py
AddThis Social Bookmark Button
Document Actions