From dbfe0d96bef5d3c80210bfddd5152cdf888986a3 Mon Sep 17 00:00:00 2001 From: Florian Pagnoux Date: Tue, 23 May 2017 21:18:09 +0200 Subject: [PATCH] Introduce --nose option in openfisca-run-test --- CHANGELOG.md | 6 ++++++ openfisca_core/scripts/run_test.py | 4 +++- openfisca_core/tools/test_runner.py | 29 ++++++++++++++++++++++------- setup.py | 2 +- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41d113149c..bb3e867f3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 12.2.0 + +* Improve the `openfisca-run-test` script + - Add a `--nose` option to run the tests with nose. + - This avoids boilerplate code on country packages, and makes parallelism easier to set on Circle CI. + ## 12.1.4 * Fix package naming conflict between the preview API and the official one. diff --git a/openfisca_core/scripts/run_test.py b/openfisca_core/scripts/run_test.py index beb511ac80..5d6dced7b8 100644 --- a/openfisca_core/scripts/run_test.py +++ b/openfisca_core/scripts/run_test.py @@ -15,6 +15,7 @@ def build_parser(): parser = add_tax_benefit_system_arguments(parser) parser.add_argument('-n', '--name_filter', default = None, help = "partial name of tests to execute. Only tests with the given name_filter in their name, file name, or keywords will be run.") parser.add_argument('-v', '--verbose', action = 'store_true', default = False, help = "increase output verbosity") + parser.add_argument('--nose', action = 'store_true', default = False, help = "use nosetests to run the tests") return parser @@ -29,6 +30,7 @@ def main(): options = { 'verbose': args.verbose, 'name_filter': args.name_filter, + 'nose': args.nose, } tests_found = False @@ -38,7 +40,7 @@ def main(): nb_tests = run_tests(tax_benefit_system, path, options) tests_found = tests_found or nb_tests > 0 - if not tests_found: + if not tests_found and not args.nose: print("No tests found!") sys.exit(1) diff --git a/openfisca_core/tools/test_runner.py b/openfisca_core/tools/test_runner.py index 2759f99a78..15842d1f4a 100644 --- a/openfisca_core/tools/test_runner.py +++ b/openfisca_core/tools/test_runner.py @@ -10,6 +10,8 @@ import os import yaml import numpy as np +import sys +import unittest from openfisca_core import conv, periods, scenarios from openfisca_core.tools import assert_near @@ -94,16 +96,26 @@ def run_tests(tax_benefit_system, path, options = {}): | verbose | ``bool`` | | +-------------------------------+-----------+ + | name_filter | ``str`` | See :any:`openfisca-run-test` options doc | + +-------------------------------+-----------+ + + | nose | ``bool`` | | +-------------------------------+-----------+-------------------------------------------+ """ + if options.get('nose'): + import nose + 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), + # Nose crashes if it gets any unexpected argument. + argv = sys.argv[:1] + ) + else: + nb_tests = 0 + for test in generate_tests(tax_benefit_system, path, options): + test() + nb_tests += 1 - nb_tests = 0 - for test in generate_tests(tax_benefit_system, path, options): - test() - nb_tests += 1 - - return nb_tests # Nb of sucessful tests + return nb_tests # Nb of sucessful tests # Internal methods @@ -137,7 +149,10 @@ def check(): print("=" * len(title)) _run_test(period_str, test, verbose, options) - yield check + if options.get('nose'): + yield unittest.FunctionTestCase(check) + else: + yield check def _generate_tests_from_directory(tax_benefit_system, path_to_dir, options): diff --git a/setup.py b/setup.py index a9e77b2fa3..e1fb3d33be 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name = 'OpenFisca-Core', - version = '12.1.4', + version = '12.2.0', author = 'OpenFisca Team', author_email = 'contact@openfisca.fr', classifiers = [