From 52ab8cc44e34bdb258a59d489d117542dc856fb7 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sat, 9 Jun 2018 12:21:54 -0700 Subject: [PATCH] test_handler: Separate test title from path to discover tests. --- tools/server_lib/test_handler.py | 8 ++++---- tools/test-botserver | 2 +- tools/test-zulip | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/server_lib/test_handler.py b/tools/server_lib/test_handler.py index a4c8f0c..72d1e3e 100644 --- a/tools/server_lib/test_handler.py +++ b/tools/server_lib/test_handler.py @@ -9,8 +9,8 @@ import pytest TOOLS_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) os.chdir(os.path.dirname(TOOLS_DIR)) -def handle_input_and_run_tests_for_package(package_name): - parser = argparse.ArgumentParser(description="Run tests for the {} package.".format(package_name)) +def handle_input_and_run_tests_for_package(package_name, path_list): + parser = argparse.ArgumentParser(description="Run tests for {}.".format(package_name)) parser.add_argument('--coverage', nargs='?', const=True, @@ -34,7 +34,7 @@ def handle_input_and_run_tests_for_package(package_name): cov.start() if options.pytest: - location_to_run_in = os.path.join(TOOLS_DIR, '..', package_name) + location_to_run_in = os.path.join(TOOLS_DIR, '..', *path_list) paths_to_test = ['.'] pytest_options = [ '-s', # show output from tests; this hides the progress bar though @@ -50,7 +50,7 @@ def handle_input_and_run_tests_for_package(package_name): else: # Codecov seems to work only when using loader.discover. It failed to capture line executions # for functions like loader.loadTestFromModule or loader.loadTestFromNames. - test_suites = unittest.defaultTestLoader.discover(package_name) + test_suites = unittest.defaultTestLoader.discover(os.path.join(*path_list)) suite = unittest.TestSuite(test_suites) runner = unittest.TextTestRunner(verbosity=2) result = runner.run(suite) diff --git a/tools/test-botserver b/tools/test-botserver index 7caf003..15bb61f 100755 --- a/tools/test-botserver +++ b/tools/test-botserver @@ -3,4 +3,4 @@ from server_lib.test_handler import handle_input_and_run_tests_for_package if __name__ == '__main__': - handle_input_and_run_tests_for_package('zulip_botserver') + handle_input_and_run_tests_for_package('Botserver', ['zulip_botserver']) diff --git a/tools/test-zulip b/tools/test-zulip index a504df0..838d4da 100755 --- a/tools/test-zulip +++ b/tools/test-zulip @@ -3,4 +3,4 @@ from server_lib.test_handler import handle_input_and_run_tests_for_package if __name__ == '__main__': - handle_input_and_run_tests_for_package('zulip') + handle_input_and_run_tests_for_package('API', ['zulip'])