Commit ea1b8cde authored by dpranke@chromium.org's avatar dpranke@chromium.org

Add --unexpected-failures flag to run_mojo_python_tests.

In order to best run a suite of tests on the bots, we need to support
printing out the list of tests that failed in an easily-machine-readable
manner, and also support running just a subset of tests.

This patch adds the --unexpected-failures flag to run_mojo_python_tests
to write out, one test name per line, a list of failures (full details
are listed in the usage for the script).

It also adds the ability to just run a subset of tests.

If we add any more complexity to this script we really need to write tests
for it.

R=sky@chromium.org
BUG=364709

Review URL: https://codereview.chromium.org/257103002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266792 0039d316-1c4b-4281-b951-d872f2087c98
parent 20f0f782
......@@ -5,21 +5,27 @@
import optparse
import os
import re
import sys
import unittest
# TODO(dpranke): crbug.com/364709 . We should add the ability to return
# JSONified results data for the bots.
def main():
parser = optparse.OptionParser()
parser.usage = 'run_mojo_python_tests.py [options] [tests...]'
parser.add_option('-v', '--verbose', action='count', default=0)
parser.add_option('--unexpected-failures', metavar='FILENAME', action='store',
help=('path to write a list of any tests that fail '
'unexpectedly.'))
parser.epilog = ('If --unexpected-failures is passed, a list of the tests '
'that failed (one per line) will be written to the file. '
'If no tests failed, the file will be truncated (empty). '
'If the test run did not completely properly, or something '
'else weird happened, any existing file will be left '
'unmodified. '
'If --unexpected-failures is *not* passed, any existing '
'file will be ignored and left unmodified.')
options, args = parser.parse_args()
if args:
parser.usage()
return 1
chromium_src_dir = os.path.join(os.path.dirname(__file__),
os.pardir,
......@@ -27,14 +33,42 @@ def main():
loader = unittest.loader.TestLoader()
print "Running Python unit tests under mojo/public/tools/bindings/pylib ..."
suite = loader.discover(os.path.join(chromium_src_dir, 'mojo', 'public',
'tools', 'bindings', 'pylib'),
pattern='*_unittest.py')
runner = unittest.runner.TextTestRunner(verbosity=(options.verbose+1))
pylib_dir = os.path.join(chromium_src_dir, 'mojo', 'public',
'tools', 'bindings', 'pylib')
if args:
if not pylib_dir in sys.path:
sys.path.append(pylib_dir)
suite = unittest.TestSuite()
for test_name in args:
suite.addTests(loader.loadTestsFromName(test_name))
else:
suite = loader.discover(pylib_dir, pattern='*_unittest.py')
runner = unittest.runner.TextTestRunner(verbosity=(options.verbose + 1))
result = runner.run(suite)
if options.unexpected_failures:
WriteUnexpectedFailures(result, options.unexpected_failures)
return 0 if result.wasSuccessful() else 1
def WriteUnexpectedFailures(result, path):
# This regex and UnitTestName() extracts the test_name in a way
# that can be handed back to the loader successfully.
test_description = re.compile("(\w+) \(([\w.]+)\)")
def UnitTestName(test):
m = test_description.match(str(test))
return "%s.%s" % (m.group(2), m.group(1))
with open(path, 'w') as fp:
for (test, _) in result.failures + result.errors:
fp.write(UnitTestName(test) + '\n')
if __name__ == '__main__':
sys.exit(main())
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment