Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: mojo/tools/run_mojo_python_tests.py

Issue 257103002: Add --unexpected-failures flag to run_mojo_python_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update w/ review feedback, merge to head Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import optparse 6 import optparse
7 import os 7 import os
8 import re
8 import sys 9 import sys
9 import unittest 10 import unittest
10 11
11 12
12 # TODO(dpranke): crbug.com/364709 . We should add the ability to return
13 # JSONified results data for the bots.
14
15
16 def main(): 13 def main():
17 parser = optparse.OptionParser() 14 parser = optparse.OptionParser()
15 parser.usage = 'run_mojo_python_tests.py [options] [tests...]'
18 parser.add_option('-v', '--verbose', action='count', default=0) 16 parser.add_option('-v', '--verbose', action='count', default=0)
17 parser.add_option('--unexpected-failures', metavar='FILENAME', action='store',
18 help=('path to write a list of any tests that fail '
19 'unexpectedly.'))
20 parser.epilog = ('If --unexpected-failures is passed, a list of the tests '
21 'that failed (one per line) will be written to the file. '
22 'If no tests failed, the file will be truncated (empty). '
23 'If the test run did not completely properly, or something '
24 'else weird happened, any existing file will be left '
25 'unmodified. '
26 'If --unexpected-failures is *not* passed, any existing '
27 'file will be ignored and left unmodified.')
19 options, args = parser.parse_args() 28 options, args = parser.parse_args()
20 if args:
21 parser.usage()
22 return 1
23 29
24 chromium_src_dir = os.path.join(os.path.dirname(__file__), 30 chromium_src_dir = os.path.join(os.path.dirname(__file__),
25 os.pardir, 31 os.pardir,
26 os.pardir) 32 os.pardir)
27 33
28 loader = unittest.loader.TestLoader() 34 loader = unittest.loader.TestLoader()
29 print "Running Python unit tests under mojo/public/tools/bindings/pylib ..." 35 print "Running Python unit tests under mojo/public/tools/bindings/pylib ..."
30 suite = loader.discover(os.path.join(chromium_src_dir, 'mojo', 'public',
31 'tools', 'bindings', 'pylib'),
32 pattern='*_unittest.py')
33 36
34 runner = unittest.runner.TextTestRunner(verbosity=(options.verbose+1)) 37 pylib_dir = os.path.join(chromium_src_dir, 'mojo', 'public',
38 'tools', 'bindings', 'pylib')
39 if args:
40 if not pylib_dir in sys.path:
41 sys.path.append(pylib_dir)
42 suite = unittest.TestSuite()
43 for test_name in args:
44 suite.addTests(loader.loadTestsFromName(test_name))
45 else:
46 suite = loader.discover(pylib_dir, pattern='*_unittest.py')
47
48 runner = unittest.runner.TextTestRunner(verbosity=(options.verbose + 1))
35 result = runner.run(suite) 49 result = runner.run(suite)
50
51 if options.unexpected_failures:
52 WriteUnexpectedFailures(result, options.unexpected_failures)
53
36 return 0 if result.wasSuccessful() else 1 54 return 0 if result.wasSuccessful() else 1
37 55
38 56
57 def WriteUnexpectedFailures(result, path):
58
59 # This regex and UnitTestName() extracts the test_name in a way
60 # that can be handed back to the loader successfully.
61
62 test_description = re.compile("(\w+) \(([\w.]+)\)")
63
64 def UnitTestName(test):
65 m = test_description.match(str(test))
66 return "%s.%s" % (m.group(2), m.group(1))
67
68 with open(path, 'w') as fp:
69 for (test, _) in result.failures + result.errors:
70 fp.write(UnitTestName(test) + '\n')
71
72
39 if __name__ == '__main__': 73 if __name__ == '__main__':
40 sys.exit(main()) 74 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698