blob: 6b5d5e67e5b9dccce03c77bc4454645561a74fc8 [file] [log] [blame]
Junji Watanabe79d1c7c2019-10-21 04:46:49 +00001#!/usr/bin/env vpython
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
6import os
7import sys
8
9import six
10
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000011THIS_DIR = os.path.dirname(os.path.abspath(__file__))
12TESTS_DIR = os.path.join(THIS_DIR, 'tests')
Junji Watanabef1cb0a92019-10-25 09:39:38 +000013LUCI_DIR = os.path.dirname(THIS_DIR)
14COMPONENTS_DIR = os.path.join(LUCI_DIR, 'appengine', 'components')
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000015
16def main():
Junji Watanabe2ebf0072019-12-02 14:36:35 +000017 sys.path.insert(0, COMPONENTS_DIR)
18
19 return run_tests_parralel() or run_tests_sequential()
20
21
22def run_tests_parralel():
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000023 sys.path.insert(0, TESTS_DIR)
24 import test_env
25 test_env.setup()
26
27 # Need to specify config path explicitly
28 # because test_env.setup() changes directory
Junji Watanabef1cb0a92019-10-25 09:39:38 +000029 cfg = os.path.join(COMPONENTS_DIR, 'test_support', 'unittest.cfg')
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000030 sys.argv.extend(['-c', cfg])
31
Junji Watanabe4b168e32019-11-28 14:38:28 +000032 # enable plugins only on linux
33 plugins = []
34 if sys.platform.startswith('linux'):
35 plugins.append('nose2.plugins.mp')
36
Junji Watanabe2ebf0072019-12-02 14:36:35 +000037 # append attribute filter option "--attribute '!no_run'"
38 # https://nose2.readthedocs.io/en/latest/plugins/attrib.html
39 from test_support import parallel_test_runner
40 sys.argv.extend(['--attribute', '!no_run'])
41
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000042 # execute test runner
Junji Watanabe4b168e32019-11-28 14:38:28 +000043 return parallel_test_runner.run_tests(python3=six.PY3, plugins=plugins)
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000044
45
Junji Watanabe2ebf0072019-12-02 14:36:35 +000046def run_tests_sequential():
47 # These tests need to be run as executable
48 # because they don't pass when running in parallel
49 # or run via test runner
50 test_files = [
51 'tests/swarming_test.py',
52 'tests/run_isolated_test.py',
53 'tests/isolateserver_test.py',
54 'tests/logging_utils_test.py',
55 ]
56 abs_test_files = [os.path.join(THIS_DIR, t) for t in test_files]
57
58 # execute test runner
59 from test_support import sequential_test_runner
60 return sequential_test_runner.run_tests(abs_test_files, python3=six.PY3)
61
62
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000063if __name__ == '__main__':
Junji Watanabe2ebf0072019-12-02 14:36:35 +000064 sys.exit(main())