blob: 7650722399ae301b991d6888c0bb81da04c7a913 [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
Junji Watanabe38b28b02020-04-23 10:23:30 +000016
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000017def main():
Junji Watanabe2ebf0072019-12-02 14:36:35 +000018 sys.path.insert(0, COMPONENTS_DIR)
19
20 return run_tests_parralel() or run_tests_sequential()
21
22
23def run_tests_parralel():
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000024 sys.path.insert(0, TESTS_DIR)
25 import test_env
26 test_env.setup()
27
28 # Need to specify config path explicitly
29 # because test_env.setup() changes directory
Junji Watanabe1cc16c42020-06-30 07:55:06 +000030 cfg = os.path.join(THIS_DIR, 'unittest.cfg')
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000031 sys.argv.extend(['-c', cfg])
32
Junji Watanabe4b168e32019-11-28 14:38:28 +000033 # enable plugins only on linux
34 plugins = []
35 if sys.platform.startswith('linux'):
36 plugins.append('nose2.plugins.mp')
37
Junji Watanabe2ebf0072019-12-02 14:36:35 +000038 # append attribute filter option "--attribute '!no_run'"
39 # https://nose2.readthedocs.io/en/latest/plugins/attrib.html
40 from test_support import parallel_test_runner
41 sys.argv.extend(['--attribute', '!no_run'])
42
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000043 # execute test runner
Junji Watanabe4b168e32019-11-28 14:38:28 +000044 return parallel_test_runner.run_tests(python3=six.PY3, plugins=plugins)
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000045
46
Junji Watanabe2ebf0072019-12-02 14:36:35 +000047def run_tests_sequential():
48 # These tests need to be run as executable
49 # because they don't pass when running in parallel
50 # or run via test runner
51 test_files = [
52 'tests/swarming_test.py',
53 'tests/run_isolated_test.py',
54 'tests/isolateserver_test.py',
55 'tests/logging_utils_test.py',
56 ]
57 abs_test_files = [os.path.join(THIS_DIR, t) for t in test_files]
58
59 # execute test runner
60 from test_support import sequential_test_runner
61 return sequential_test_runner.run_tests(abs_test_files, python3=six.PY3)
62
63
Junji Watanabe79d1c7c2019-10-21 04:46:49 +000064if __name__ == '__main__':
Junji Watanabe2ebf0072019-12-02 14:36:35 +000065 sys.exit(main())