Igor Murashkin | 5d278fd | 2018-08-14 12:48:35 -0700 | [diff] [blame] | 1 | # Copyright 2018 Google Inc. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | import os |
| 16 | import sys |
| 17 | import unittest |
| 18 | |
| 19 | # this runs any test*.py files located anywhere in this subtree |
| 20 | if __name__ == '__main__': |
| 21 | test_loader = unittest.defaultTestLoader |
| 22 | # output is normal text formatting (as if running from a CLI), prints to stderr |
| 23 | test_runner = unittest.TextTestRunner(stream=sys.stderr) |
| 24 | |
| 25 | # look at tests relative to the dir of this file. |
| 26 | this_dir = os.path.dirname(os.path.abspath(__file__)) |
| 27 | |
| 28 | # automagically find all tests recursively whose file name matches test*.py |
| 29 | test_suite = test_loader.discover(this_dir, pattern='test*.py') |
| 30 | |
| 31 | # execute all the found tests |
| 32 | test_runner.run(test_suite) |
| 33 | |