def list_tests(context, verbose, test_dirs): """ Print a list of test files or test cases. If verbose option selected, print all tests cases in each test file, otherwise print the test files only. If test_dirs supplied they will be used to search for tests otherwise the default test directories are used. """ no_color = context.obj['no_color'] test_dirs = test_dirs or TEST_PATHS try: results = collect_tests(test_dirs, verbose) except Exception as error: echo_style("An error occurred retrieving test files: {}".format(error), no_color, fg='red') sys.exit(1) if verbose: for index, test_file in enumerate(results): if index % 2 == 0: fg = 'blue' else: fg = 'green' echo_style('\n'.join(test_file), no_color, fg=fg) else: click.echo('\n'.join(results))
def test_collect_tests_no_dirs(mock_os): """Test collect tests default directories do not exist.""" mock_os.path.exists.return_value = False with raises(IpaControllerException): collect_tests(verbose=True)