Mike Frysinger | 1b117db | 2020-02-08 03:38:48 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
Mike Frysinger | 4f42a97 | 2019-06-12 17:42:43 -0400 | [diff] [blame] | 2 | # -*- coding:utf-8 -*- |
| 3 | # Copyright 2019 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | """Wrapper to run pytest with the right settings.""" |
| 18 | |
| 19 | from __future__ import print_function |
| 20 | |
| 21 | import errno |
| 22 | import os |
| 23 | import subprocess |
| 24 | import sys |
| 25 | |
| 26 | |
| 27 | def run_pytest(cmd, argv): |
| 28 | """Run the unittests via |cmd|.""" |
| 29 | try: |
Mike Frysinger | 6f8c85c | 2019-12-01 22:42:14 -0500 | [diff] [blame] | 30 | return subprocess.call([cmd] + argv) |
Mike Frysinger | 4f42a97 | 2019-06-12 17:42:43 -0400 | [diff] [blame] | 31 | except OSError as e: |
| 32 | if e.errno == errno.ENOENT: |
| 33 | print('%s: unable to run `%s`: %s' % (__file__, cmd, e), file=sys.stderr) |
| 34 | print('%s: Try installing pytest: sudo apt-get install python-pytest' % |
| 35 | (__file__,), file=sys.stderr) |
Mike Frysinger | 6f8c85c | 2019-12-01 22:42:14 -0500 | [diff] [blame] | 36 | return 127 |
Mike Frysinger | 4f42a97 | 2019-06-12 17:42:43 -0400 | [diff] [blame] | 37 | else: |
| 38 | raise |
| 39 | |
| 40 | |
| 41 | def main(argv): |
| 42 | """The main entry.""" |
| 43 | # Add the repo tree to PYTHONPATH as the tests expect to be able to import |
| 44 | # modules directly. |
Mike Frysinger | d216384 | 2020-02-15 13:44:56 -0500 | [diff] [blame] | 45 | pythonpath = os.path.dirname(os.path.realpath(__file__)) |
| 46 | oldpythonpath = os.environ.get('PYTHONPATH', None) |
| 47 | if oldpythonpath is not None: |
| 48 | pythonpath += os.pathsep + oldpythonpath |
| 49 | os.environ['PYTHONPATH'] = pythonpath |
Mike Frysinger | 4f42a97 | 2019-06-12 17:42:43 -0400 | [diff] [blame] | 50 | |
| 51 | return run_pytest('pytest', argv) |
| 52 | |
| 53 | |
| 54 | if __name__ == '__main__': |
| 55 | sys.exit(main(sys.argv[1:])) |