diff options
author | dpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-29 09:03:10 +0000 |
---|---|---|
committer | dpranke@chromium.org <dpranke@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-29 09:03:10 +0000 |
commit | ea1b8cde7e2d4d0c3b0fd59491efc1ce46b020ce (patch) | |
tree | 8d7a418ecf04fb17fcfa3f583c893a9f3408e540 /mojo/tools/run_mojo_python_tests.py | |
parent | 20f0f782b34d677c7c7e83d2d433e9b0869fcb04 (diff) | |
download | chromium_src-ea1b8cde7e2d4d0c3b0fd59491efc1ce46b020ce.zip chromium_src-ea1b8cde7e2d4d0c3b0fd59491efc1ce46b020ce.tar.gz chromium_src-ea1b8cde7e2d4d0c3b0fd59491efc1ce46b020ce.tar.bz2 |
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
Diffstat (limited to 'mojo/tools/run_mojo_python_tests.py')
-rwxr-xr-x | mojo/tools/run_mojo_python_tests.py | 56 |
1 files changed, 45 insertions, 11 deletions
diff --git a/mojo/tools/run_mojo_python_tests.py b/mojo/tools/run_mojo_python_tests.py index 2bee0ab..c96aba3 100755 --- a/mojo/tools/run_mojo_python_tests.py +++ b/mojo/tools/run_mojo_python_tests.py @@ -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()) |