OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 logging | 4 import logging |
5 import unittest | 5 import unittest |
6 | 6 |
7 from telemetry.core import browser_options | 7 from telemetry.core import browser_options |
8 from telemetry.core import discover | 8 from telemetry.core import discover |
9 from telemetry.core import util | 9 from telemetry.core import util |
10 from telemetry.unittest import gtest_testrunner | 10 from telemetry.unittest import gtest_testrunner |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 | 75 |
76 return True | 76 return True |
77 | 77 |
78 filtered_suite = FilterSuite(suite, IsTestSelected) | 78 filtered_suite = FilterSuite(suite, IsTestSelected) |
79 test_result = runner.run(filtered_suite) | 79 test_result = runner.run(filtered_suite) |
80 return test_result | 80 return test_result |
81 | 81 |
82 | 82 |
83 def Main(args, start_dir, top_level_dir, runner=None): | 83 def Main(args, start_dir, top_level_dir, runner=None): |
84 """Unit test suite that collects all test cases for telemetry.""" | 84 """Unit test suite that collects all test cases for telemetry.""" |
85 # Cache the current logging level, this needs to be done before calling | |
86 # parser.parse_args, which changes logging level based on verbosity setting. | |
87 logging_level = logging.getLogger().getEffectiveLevel() | |
85 # Add unittest_data to the path so we can import packages from it. | 88 # Add unittest_data to the path so we can import packages from it. |
86 util.AddDirToPythonPath(util.GetUnittestDataDir()) | 89 util.AddDirToPythonPath(util.GetUnittestDataDir()) |
87 | 90 |
88 default_options = browser_options.BrowserFinderOptions() | 91 default_options = browser_options.BrowserFinderOptions() |
89 default_options.browser_type = 'any' | 92 default_options.browser_type = 'any' |
90 | 93 |
91 parser = default_options.CreateParser('run_tests [options] [test names]') | 94 parser = default_options.CreateParser('run_tests [options] [test names]') |
92 parser.add_option('--repeat-count', dest='run_test_repeat_count', | 95 parser.add_option('--repeat-count', dest='run_test_repeat_count', |
93 type='int', default=1, | 96 type='int', default=1, |
94 help='Repeats each a provided number of times.') | 97 help='Repeats each a provided number of times.') |
95 parser.add_option('-d', '--also-run-disabled-tests', | 98 parser.add_option('-d', '--also-run-disabled-tests', |
96 dest='run_disabled_tests', | 99 dest='run_disabled_tests', |
97 action='store_true', default=False, | 100 action='store_true', default=False, |
98 help='Also run tests decorated with @DisabledTest.') | 101 help='Also run tests decorated with @DisabledTest.') |
99 | 102 |
100 _, args = parser.parse_args(args) | 103 _, args = parser.parse_args(args) |
101 | 104 |
102 logging_level = logging.getLogger().getEffectiveLevel() | |
103 if default_options.verbosity == 0: | 105 if default_options.verbosity == 0: |
104 logging.getLogger().setLevel(logging.WARN) | 106 logging.getLogger().setLevel(logging.WARN) |
105 | 107 |
106 from telemetry.core import browser_finder | 108 from telemetry.core import browser_finder |
107 try: | 109 try: |
108 browser_to_create = browser_finder.FindBrowser(default_options) | 110 browser_to_create = browser_finder.FindBrowser(default_options) |
109 except browser_finder.BrowserFinderException, ex: | 111 except browser_finder.BrowserFinderException, ex: |
110 logging.error(str(ex)) | 112 logging.error(str(ex)) |
111 return 1 | 113 return 1 |
112 | 114 |
113 if browser_to_create == None: | 115 if browser_to_create == None: |
114 logging.error('No browser found of type %s. Cannot run tests.', | 116 logging.error('No browser found of type %s. Cannot run tests.', |
115 default_options.browser_type) | 117 default_options.browser_type) |
116 logging.error('Re-run with --browser=list to see available browser types.') | 118 logging.error('Re-run with --browser=list to see available browser types.') |
117 return 1 | 119 return 1 |
118 | 120 |
119 options_for_unittests.Set(default_options, | 121 options_for_unittests.Set(default_options, |
120 browser_to_create.browser_type) | 122 browser_to_create.browser_type) |
121 try: | 123 try: |
122 success = True | 124 success = True |
123 for _ in range( | 125 for _ in range( |
124 default_options.run_test_repeat_count): # pylint: disable=E1101 | 126 default_options.run_test_repeat_count): # pylint: disable=E1101 |
125 success = success and DiscoverAndRunTests( | 127 success = success and DiscoverAndRunTests( |
126 start_dir, args, top_level_dir, | 128 start_dir, args, top_level_dir, |
127 runner, default_options.run_disabled_tests) | 129 runner, default_options.run_disabled_tests) |
128 if success: | 130 if success: |
129 return 0 | 131 return 0 |
130 finally: | 132 finally: |
131 options_for_unittests.Set(None, None) | 133 options_for_unittests.Set(None, None) |
132 if default_options.verbosity == 0: | 134 # Restore logging level, which may be changed in parser.parse_args. |
133 # Restore logging level. | 135 logging.getLogger().setLevel(logging_level) |
dtu
2013/09/12 21:45:51
Theoretically, you want this try/finally to go aro
dshi
2013/09/13 20:28:34
Done.
| |
134 logging.getLogger().setLevel(logging_level) | |
135 | 136 |
136 return 1 | 137 return 1 |
OLD | NEW |