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

Side by Side Diff: tools/telemetry/telemetry/unittest_util/run_tests.py

Issue 942663002: [Telemetry] Pass test_runner environment in local args instead of a global variable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix find_dependencies issue Created 5 years, 9 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
OLDNEW
1 # Copyright 2012 The Chromium Authors. All rights reserved. 1 # Copyright 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 import sys 4 import sys
5 5
6 from telemetry import decorators 6 from telemetry import decorators
7 from telemetry.core import browser_finder 7 from telemetry.core import browser_finder
8 from telemetry.core import browser_finder_exceptions 8 from telemetry.core import browser_finder_exceptions
9 from telemetry.core import browser_options 9 from telemetry.core import browser_options
10 from telemetry.core import command_line 10 from telemetry.core import command_line
(...skipping 17 matching lines...) Expand all
28 self.stream = sys.stdout 28 self.stream = sys.stdout
29 29
30 @classmethod 30 @classmethod
31 def CreateParser(cls): 31 def CreateParser(cls):
32 options = browser_options.BrowserFinderOptions() 32 options = browser_options.BrowserFinderOptions()
33 options.browser_type = 'any' 33 options.browser_type = 'any'
34 parser = options.CreateParser('%%prog %s' % cls.usage) 34 parser = options.CreateParser('%%prog %s' % cls.usage)
35 return parser 35 return parser
36 36
37 @classmethod 37 @classmethod
38 def AddCommandLineArgs(cls, parser): 38 def AddCommandLineArgs(cls, parser, _):
39 parser.add_option('--repeat-count', type='int', default=1, 39 parser.add_option('--repeat-count', type='int', default=1,
40 help='Repeats each a provided number of times.') 40 help='Repeats each a provided number of times.')
41 parser.add_option('-d', '--also-run-disabled-tests', 41 parser.add_option('-d', '--also-run-disabled-tests',
42 dest='run_disabled_tests', 42 dest='run_disabled_tests',
43 action='store_true', default=False, 43 action='store_true', default=False,
44 help='Ignore @Disabled and @Enabled restrictions.') 44 help='Ignore @Disabled and @Enabled restrictions.')
45 parser.add_option('--exact-test-filter', action='store_true', default=False, 45 parser.add_option('--exact-test-filter', action='store_true', default=False,
46 help='Treat test filter as exact matches (default is ' 46 help='Treat test filter as exact matches (default is '
47 'substring matches).') 47 'substring matches).')
48 48
49 typ.ArgumentParser.add_option_group(parser, 49 typ.ArgumentParser.add_option_group(parser,
50 "Options for running the tests", 50 "Options for running the tests",
51 running=True, 51 running=True,
52 skip=['-d', '-v', '--verbose']) 52 skip=['-d', '-v', '--verbose'])
53 typ.ArgumentParser.add_option_group(parser, 53 typ.ArgumentParser.add_option_group(parser,
54 "Options for reporting the results", 54 "Options for reporting the results",
55 reporting=True) 55 reporting=True)
56 56
57 @classmethod 57 @classmethod
58 def ProcessCommandLineArgs(cls, parser, args): 58 def ProcessCommandLineArgs(cls, parser, args, _):
59 # We retry failures by default unless we're running a list of tests 59 # We retry failures by default unless we're running a list of tests
60 # explicitly. 60 # explicitly.
61 if not args.retry_limit and not args.positional_args: 61 if not args.retry_limit and not args.positional_args:
62 args.retry_limit = 3 62 args.retry_limit = 3
63 63
64 try: 64 try:
65 possible_browser = browser_finder.FindBrowser(args) 65 possible_browser = browser_finder.FindBrowser(args)
66 except browser_finder_exceptions.BrowserFinderException, ex: 66 except browser_finder_exceptions.BrowserFinderException, ex:
67 parser.error(ex) 67 parser.error(ex)
68 68
69 if not possible_browser: 69 if not possible_browser:
70 parser.error('No browser found of type %s. Cannot run tests.\n' 70 parser.error('No browser found of type %s. Cannot run tests.\n'
71 'Re-run with --browser=list to see ' 71 'Re-run with --browser=list to see '
72 'available browser types.' % args.browser_type) 72 'available browser types.' % args.browser_type)
73 73
74 @classmethod 74 @classmethod
75 def main(cls, args=None, stream=None): # pylint: disable=W0221 75 def main(cls, args=None, stream=None): # pylint: disable=W0221
76 # We override the superclass so that we can hook in the 'stream' arg. 76 # We override the superclass so that we can hook in the 'stream' arg.
77 parser = cls.CreateParser() 77 parser = cls.CreateParser()
78 cls.AddCommandLineArgs(parser) 78 cls.AddCommandLineArgs(parser, None)
79 options, positional_args = parser.parse_args(args) 79 options, positional_args = parser.parse_args(args)
80 options.positional_args = positional_args 80 options.positional_args = positional_args
81 cls.ProcessCommandLineArgs(parser, options) 81 cls.ProcessCommandLineArgs(parser, options, None)
82 82
83 obj = cls() 83 obj = cls()
84 if stream is not None: 84 if stream is not None:
85 obj.stream = stream 85 obj.stream = stream
86 return obj.Run(options) 86 return obj.Run(options)
87 87
88 def Run(self, args): 88 def Run(self, args):
89 possible_browser = browser_finder.FindBrowser(args) 89 possible_browser = browser_finder.FindBrowser(args)
90 90
91 runner = typ.Runner() 91 runner = typ.Runner()
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 183
184 def _TearDownProcess(child, context): # pylint: disable=W0613 184 def _TearDownProcess(child, context): # pylint: disable=W0613
185 browser_test_case.teardown_browser() 185 browser_test_case.teardown_browser()
186 options_for_unittests.Pop() 186 options_for_unittests.Pop()
187 187
188 188
189 if __name__ == '__main__': 189 if __name__ == '__main__':
190 ret_code = RunTestsCommand.main() 190 ret_code = RunTestsCommand.main()
191 sys.exit(ret_code) 191 sys.exit(ret_code)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/core/environment.py ('k') | tools/telemetry/telemetry/util/find_dependencies.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698