From 020ff1765a222b9e802ab2cb316312eb70e05502 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Fri, 7 Jun 2019 16:22:06 +0300 Subject: [PATCH] Add an entry point to discover and run helpers tests with teamcity-messages Utilize it to run tests on TC instead of plain "-m unittest discover". GitOrigin-RevId: e021c4f5dd01f5a5b9b0d989d6befd795e394499 --- python/helpers/tests/__main__.py | 23 +++++++++++++++++++++++ python/helpers/tests/build.gradle | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 python/helpers/tests/__main__.py diff --git a/python/helpers/tests/__main__.py b/python/helpers/tests/__main__.py new file mode 100644 index 000000000000..4edba9864788 --- /dev/null +++ b/python/helpers/tests/__main__.py @@ -0,0 +1,23 @@ +import os +import sys +import unittest + +_tests_dir = os.path.dirname(os.path.abspath(__file__)) +_helpers_dir = os.path.dirname(_tests_dir) + + +def discover_and_run_tests(): + suite = unittest.TestLoader().discover(_tests_dir) + runner = unittest.TextTestRunner() + try: + import teamcity.unittestpy + if teamcity.is_running_under_teamcity(): + runner = teamcity.unittestpy.TeamcityTestRunner() + except ImportError: + pass + runner.run(suite) + + +if __name__ == '__main__': + sys.path.append(_helpers_dir) + discover_and_run_tests() diff --git a/python/helpers/tests/build.gradle b/python/helpers/tests/build.gradle index c9a878cdb8ae..9fba03b7788c 100644 --- a/python/helpers/tests/build.gradle +++ b/python/helpers/tests/build.gradle @@ -23,7 +23,7 @@ envs { mustRunAfter 'build_envs' environment PYTHONPATH: ".:.." - commandLine new File(pythonDirectory, pythonName).absolutePath + '/bin/python', '-m', 'unittest' + commandLine new File(pythonDirectory, pythonName).absolutePath + '/bin/python', '__main__.py' } }