Junji Watanabe | 84b8279 | 2022-01-13 07:18:00 +0000 | [diff] [blame] | 1 | #!/usr/bin/env vpython3 |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 2 | # Copyright 2019 The LUCI Authors. All rights reserved. |
| 3 | # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 | # that can be found in the LICENSE file. |
| 5 | |
| 6 | import os |
| 7 | import sys |
| 8 | |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 9 | THIS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 10 | TESTS_DIR = os.path.join(THIS_DIR, 'tests') |
Junji Watanabe | f1cb0a9 | 2019-10-25 09:39:38 +0000 | [diff] [blame] | 11 | LUCI_DIR = os.path.dirname(THIS_DIR) |
| 12 | COMPONENTS_DIR = os.path.join(LUCI_DIR, 'appengine', 'components') |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 13 | |
Junji Watanabe | 38b28b0 | 2020-04-23 10:23:30 +0000 | [diff] [blame] | 14 | |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 15 | def main(): |
Junji Watanabe | 2ebf007 | 2019-12-02 14:36:35 +0000 | [diff] [blame] | 16 | sys.path.insert(0, COMPONENTS_DIR) |
| 17 | |
| 18 | return run_tests_parralel() or run_tests_sequential() |
| 19 | |
| 20 | |
| 21 | def run_tests_parralel(): |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 22 | sys.path.insert(0, TESTS_DIR) |
| 23 | import test_env |
| 24 | test_env.setup() |
| 25 | |
| 26 | # Need to specify config path explicitly |
| 27 | # because test_env.setup() changes directory |
Junji Watanabe | 1cc16c4 | 2020-06-30 07:55:06 +0000 | [diff] [blame] | 28 | cfg = os.path.join(THIS_DIR, 'unittest.cfg') |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 29 | sys.argv.extend(['-c', cfg]) |
| 30 | |
Junji Watanabe | 4b168e3 | 2019-11-28 14:38:28 +0000 | [diff] [blame] | 31 | # enable plugins only on linux |
| 32 | plugins = [] |
Takuto Ikuta | 23388f5 | 2022-02-01 01:39:00 +0000 | [diff] [blame] | 33 | if sys.platform == 'linux': |
Junji Watanabe | 4b168e3 | 2019-11-28 14:38:28 +0000 | [diff] [blame] | 34 | plugins.append('nose2.plugins.mp') |
| 35 | |
Junji Watanabe | 2ebf007 | 2019-12-02 14:36:35 +0000 | [diff] [blame] | 36 | # append attribute filter option "--attribute '!no_run'" |
| 37 | # https://nose2.readthedocs.io/en/latest/plugins/attrib.html |
| 38 | from test_support import parallel_test_runner |
| 39 | sys.argv.extend(['--attribute', '!no_run']) |
| 40 | |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 41 | # execute test runner |
Junji Watanabe | 84b8279 | 2022-01-13 07:18:00 +0000 | [diff] [blame] | 42 | return parallel_test_runner.run_tests(python3=True, plugins=plugins) |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 43 | |
| 44 | |
Junji Watanabe | 2ebf007 | 2019-12-02 14:36:35 +0000 | [diff] [blame] | 45 | def run_tests_sequential(): |
| 46 | # These tests need to be run as executable |
| 47 | # because they don't pass when running in parallel |
| 48 | # or run via test runner |
Junji Watanabe | cfb699b | 2020-07-13 01:38:26 +0000 | [diff] [blame] | 49 | abs_path = lambda f: os.path.join(THIS_DIR, f) |
| 50 | test_cmds = [ |
| 51 | [abs_path('tests/swarming_test.py')], |
| 52 | [abs_path('tests/run_isolated_test.py')], |
Junji Watanabe | cfb699b | 2020-07-13 01:38:26 +0000 | [diff] [blame] | 53 | [abs_path('tests/logging_utils_test.py')], |
Junji Watanabe | 2ebf007 | 2019-12-02 14:36:35 +0000 | [diff] [blame] | 54 | ] |
Junji Watanabe | 2ebf007 | 2019-12-02 14:36:35 +0000 | [diff] [blame] | 55 | |
| 56 | # execute test runner |
| 57 | from test_support import sequential_test_runner |
Junji Watanabe | 84b8279 | 2022-01-13 07:18:00 +0000 | [diff] [blame] | 58 | return sequential_test_runner.run_tests(test_cmds, python3=True) |
Junji Watanabe | 2ebf007 | 2019-12-02 14:36:35 +0000 | [diff] [blame] | 59 | |
| 60 | |
Junji Watanabe | 79d1c7c | 2019-10-21 04:46:49 +0000 | [diff] [blame] | 61 | if __name__ == '__main__': |
Junji Watanabe | 2ebf007 | 2019-12-02 14:36:35 +0000 | [diff] [blame] | 62 | sys.exit(main()) |