diff --git a/openfisca_core/scripts/run_test.py b/openfisca_core/scripts/run_test.py index 6a6e7eb9e0..848800c4ef 100644 --- a/openfisca_core/scripts/run_test.py +++ b/openfisca_core/scripts/run_test.py @@ -31,11 +31,8 @@ def main(): 'name_filter': args.name_filter, } - tests_ok = True - for path in args.path: - path = os.path.abspath(path) - test_ok = run_tests(tax_benefit_system, path, options) - tests_ok = tests_ok and test_ok + paths = map(os.path.abspath, args.path) + tests_ok = run_tests(tax_benefit_system, paths, options) if not tests_ok: sys.exit(1) diff --git a/openfisca_core/tools/test_runner.py b/openfisca_core/tools/test_runner.py index 9e996022b0..2b1334a573 100644 --- a/openfisca_core/tools/test_runner.py +++ b/openfisca_core/tools/test_runner.py @@ -60,7 +60,7 @@ def dict_constructor(loader, node): # Exposed methods -def generate_tests(tax_benefit_system, path, options = {}): +def generate_tests(tax_benefit_system, paths, options = {}): """ Generates a lazy iterator of all the YAML tests contained in a file or a directory. @@ -70,20 +70,26 @@ def generate_tests(tax_benefit_system, path, options = {}): """ - if os.path.isdir(path): - return _generate_tests_from_directory(tax_benefit_system, path, options) - else: - return _generate_tests_from_file(tax_benefit_system, path, options) + if isinstance(paths, str): + paths = [paths] + for path in paths: + if os.path.isdir(path): + for test in _generate_tests_from_directory(tax_benefit_system, path, options): + yield test + else: + for test in _generate_tests_from_file(tax_benefit_system, path, options): + yield test -def run_tests(tax_benefit_system, path, options = {}): + +def run_tests(tax_benefit_system, paths, options = {}): """ Runs all the YAML tests contained in a file or a directory. If `path` is a directory, subdirectories will be recursively explored. :param TaxBenefitSystem tax_benefit_system: the tax-benefit system to use to run the tests - :param str path: the path towards the file or directory containing thes tests. If it is a directory, subdirectories will be recursively explored. + :param (str/list) paths: A path, or a list of paths, towards the files or directories containing the tests to run. If a path is a directory, subdirectories will be recursively explored. :param dict options: See more details below. :raises AssertionError: if a test does not pass @@ -103,7 +109,7 @@ def run_tests(tax_benefit_system, path, options = {}): """ return nose.run( # The suite argument must be a lambda for nose to run the tests lazily - suite = lambda: generate_tests(tax_benefit_system, path, options), + suite = lambda: generate_tests(tax_benefit_system, paths, options), # Nose crashes if it gets any unexpected argument. argv = sys.argv[:1], # testRunner = nose.core.TextTestRunner(stream = open(os.devnull, 'w')),