test_handler: Separate test title from path to discover tests.

This commit is contained in:
neiljp (Neil Pilgrim) 2018-06-09 12:21:54 -07:00 committed by showell
parent a6a5da2653
commit 52ab8cc44e
3 changed files with 6 additions and 6 deletions

View file

@ -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)

View file

@ -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'])

View file

@ -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'])