Skip to content

Commit

Permalink
Group tests in output
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagnoux committed May 29, 2017
1 parent 58411e8 commit 1bbafd3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
7 changes: 2 additions & 5 deletions openfisca_core/scripts/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 14 additions & 8 deletions openfisca_core/tools/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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')),
Expand Down

0 comments on commit 1bbafd3

Please sign in to comment.