Skip to content

Instantly share code, notes, and snippets.

@rtyler
Created July 18, 2009 22:44
Show Gist options
  • Select an option

  • Save rtyler/149717 to your computer and use it in GitHub Desktop.

Select an option

Save rtyler/149717 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import doctest
import sys
import unittest
from optparse import OptionParser
from util import context
from qa.rc import startup
import xmlrunner
def main():
op = OptionParser()
op.add_option('--xml', dest='xml', action='store_true', help='Generate an XML file of test results (Doctests.xml)')
op.add_option('--testfiles', dest='testfiles', action='store_true', help='Run the doctests purely as doctests, instead of packaging them in unit test classes')
op.add_option('-v', dest='verbose', action='store_true', help='Turn on doctest verbosity')
opts, args = op.parse_args()
if opts.xml and opts.testfiles:
op.error('The --xml and --testfiles options are mutually exclusive')
files = []
for index, arg in enumerate(sys.argv):
if arg.endswith('.doctest'):
files.append(arg)
sys.argv = [a for a in sys.argv if not a.endswith('.doctest')]
# NOTE: If you need additional globals, add them
# into this dictionary for the doctests
doctest_globals = {}
doctest_globals.update(startup.STAGE1)
suite = unittest.TestSuite()
for file in files:
if opts.testfiles:
doctest.testfile(file, globs=doctest_globals)
else:
suite.addTest(doctest.DocFileSuite(file, globs=doctest_globals))
if opts.testfiles:
return
runner = unittest.TextTestRunner()
if opts.xml:
runner = xmlrunner.XMLTestRunner(filename='Doctests.xml')
runner.run(suite)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment