OLD | NEW |
---|---|
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
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 """Encapsulates running tests defined in tests.py. | 6 """Encapsulates running tests defined in tests.py. |
7 | 7 |
8 Running this script requires passing --config-path with a path to a config file | 8 Running this script requires passing --config-path with a path to a config file |
9 of the following structure: | 9 of the following structure: |
10 | 10 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 sorted([name for name in failed_tests])) | 105 sorted([name for name in failed_tests])) |
106 | 106 |
107 | 107 |
108 def RunTestCaseOnWebsite((website, test_case, config)): | 108 def RunTestCaseOnWebsite((website, test_case, config)): |
109 """ Runs a |test_case| on a |website|. In case when |test_case| has | 109 """ Runs a |test_case| on a |website|. In case when |test_case| has |
110 failed it tries to rerun it. If run takes too long, then it is stopped. | 110 failed it tries to rerun it. If run takes too long, then it is stopped. |
111 """ | 111 """ |
112 | 112 |
113 profile_path = tempfile.mkdtemp() | 113 profile_path = tempfile.mkdtemp() |
114 # The tests can be flaky. This is why we try to rerun up to 3 times. | 114 # The tests can be flaky. This is why we try to rerun up to 3 times. |
115 attempts = 3 | 115 attempts = 1 |
vabr (Chromium)
2015/05/18 16:13:34
Did you mean to revert the changes in this file?
melandory
2015/05/19 08:06:34
Done.
| |
116 result = ("", "", False, "") | 116 result = ("", "", False, "") |
117 logger = logging.getLogger("run_tests") | 117 logger = logging.getLogger("run_tests") |
118 for _ in xrange(attempts): | 118 for _ in xrange(attempts): |
119 shutil.rmtree(path=profile_path, ignore_errors=True) | 119 shutil.rmtree(path=profile_path, ignore_errors=True) |
120 logger.log(SCRIPT_DEBUG, "Run of test case %s of website %s started", | 120 logger.log(SCRIPT_DEBUG, "Run of test case %s of website %s started", |
121 test_case, website) | 121 test_case, website) |
122 try: | 122 #try: |
123 if True: | |
123 with stopit.ThreadingTimeout(100) as timeout: | 124 with stopit.ThreadingTimeout(100) as timeout: |
124 logger.log(SCRIPT_DEBUG, | 125 logger.log(SCRIPT_DEBUG, |
125 "Run test with parameters: %s %s %s %s %s %s", | 126 "Run test with parameters: %s %s %s %s %s %s", |
126 config.chrome_path, config.chromedriver_path, | 127 config.chrome_path, config.chromedriver_path, |
127 profile_path, config.passwords_path, | 128 profile_path, config.passwords_path, |
128 website, test_case) | 129 website, test_case) |
129 result = tests.RunTest(config.chrome_path, config.chromedriver_path, | 130 result = tests.RunTest(config.chrome_path, config.chromedriver_path, |
130 profile_path, config.passwords_path, | 131 profile_path, config.passwords_path, |
131 website, test_case)[0] | 132 website, test_case)[0] |
132 if timeout != timeout.EXECUTED: | 133 if timeout != timeout.EXECUTED: |
133 result = (website, test_case, False, "Timeout") | 134 result = (website, test_case, False, "Timeout") |
134 _, _, success, _ = result | 135 _, _, success, _ = result |
135 if success: | 136 if success: |
136 return result | 137 return result |
137 except Exception as e: | 138 #except Exception as e: |
138 result = (website, test_case, False, e) | 139 # result = (website, test_case, False, e) |
139 return result | 140 return result |
140 | 141 |
141 | 142 |
142 def RunTests(config_path): | 143 def RunTests(config_path): |
143 """Runs automated tests. | 144 """Runs automated tests. |
144 | 145 |
145 Runs the tests and returns the results through logging: | 146 Runs the tests and returns the results through logging: |
146 On logging.INFO logging level, it returns the summary of how many tests | 147 On logging.INFO logging level, it returns the summary of how many tests |
147 passed and failed. | 148 passed and failed. |
148 On logging.DEBUG logging level, it returns the failure logs, if any. | 149 On logging.DEBUG logging level, it returns the failure logs, if any. |
(...skipping 26 matching lines...) Expand all Loading... | |
175 def main(): | 176 def main(): |
176 parser = argparse.ArgumentParser() | 177 parser = argparse.ArgumentParser() |
177 parser.add_argument("config_path", metavar="N", | 178 parser.add_argument("config_path", metavar="N", |
178 help="Path to the config.ini file.") | 179 help="Path to the config.ini file.") |
179 args = parser.parse_args() | 180 args = parser.parse_args() |
180 RunTests(args.config_path) | 181 RunTests(args.config_path) |
181 | 182 |
182 | 183 |
183 if __name__ == "__main__": | 184 if __name__ == "__main__": |
184 main() | 185 main() |
OLD | NEW |