blob: bc036693efb0e8620a844db467dfd466d46e6952 [file] [log] [blame]
Junji Watanabe84b82792022-01-13 07:18:00 +00001#!/usr/bin/env vpython3
Junji Watanabe79d1c7c2019-10-21 04:46:49 +00002# 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
6import os
7import sys
8
Junji Watanabe79d1c7c2019-10-21 04:46:49 +00009THIS_DIR = os.path.dirname(os.path.abspath(__file__))
10TESTS_DIR = os.path.join(THIS_DIR, 'tests')
Junji Watanabef1cb0a92019-10-25 09:39:38 +000011LUCI_DIR = os.path.dirname(THIS_DIR)
12COMPONENTS_DIR = os.path.join(LUCI_DIR, 'appengine', 'components')
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000013
Junji Watanabe38b28b02020-04-23 10:23:30 +000014
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000015def main():
Junji Watanabe2ebf0072019-12-02 14:36:35 +000016 sys.path.insert(0, COMPONENTS_DIR)
17
18 return run_tests_parralel() or run_tests_sequential()
19
20
21def run_tests_parralel():
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000022 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 Watanabe1cc16c42020-06-30 07:55:06 +000028 cfg = os.path.join(THIS_DIR, 'unittest.cfg')
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000029 sys.argv.extend(['-c', cfg])
30
Junji Watanabe4b168e32019-11-28 14:38:28 +000031 # enable plugins only on linux
32 plugins = []
Takuto Ikuta23388f52022-02-01 01:39:00 +000033 if sys.platform == 'linux':
Junji Watanabe4b168e32019-11-28 14:38:28 +000034 plugins.append('nose2.plugins.mp')
35
Junji Watanabe2ebf0072019-12-02 14:36:35 +000036 # 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 Watanabe79d1c7c2019-10-21 04:46:49 +000041 # execute test runner
Junji Watanabe84b82792022-01-13 07:18:00 +000042 return parallel_test_runner.run_tests(python3=True, plugins=plugins)
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000043
44
Junji Watanabe2ebf0072019-12-02 14:36:35 +000045def 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 Watanabecfb699b2020-07-13 01:38:26 +000049 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 Watanabecfb699b2020-07-13 01:38:26 +000053 [abs_path('tests/logging_utils_test.py')],
Junji Watanabe2ebf0072019-12-02 14:36:35 +000054 ]
Junji Watanabe2ebf0072019-12-02 14:36:35 +000055
56 # execute test runner
57 from test_support import sequential_test_runner
Junji Watanabe84b82792022-01-13 07:18:00 +000058 return sequential_test_runner.run_tests(test_cmds, python3=True)
Junji Watanabe2ebf0072019-12-02 14:36:35 +000059
60
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000061if __name__ == '__main__':
Junji Watanabe2ebf0072019-12-02 14:36:35 +000062 sys.exit(main())