From 32759cfc909628ccfd246cebdd7930a0c4359335 Mon Sep 17 00:00:00 2001 From: ChillarAnand Date: Wed, 25 Aug 2021 08:02:02 +0530 Subject: [PATCH] fix: Passed failfast flag to unit test runner in all scenarios --- frappe/commands/utils.py | 2 +- frappe/test_runner.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index f2395ae490..2092071198 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -524,7 +524,7 @@ def console(context): @click.option('--skip-test-records', is_flag=True, default=False, help="Don't create test records") @click.option('--skip-before-tests', is_flag=True, default=False, help="Don't run before tests hook") @click.option('--junit-xml-output', help="Destination file path for junit xml report") -@click.option('--failfast', is_flag=True, default=False) +@click.option('--failfast', is_flag=True, default=False, help="Stop the test run on the first error or failure") @pass_context def run_tests(context, app=None, module=None, doctype=None, test=(), profile=False, coverage=False, junit_xml_output=False, ui_tests = False, doctype_list_path=None, diff --git a/frappe/test_runner.py b/frappe/test_runner.py index 8112362f34..ed46c9c071 100644 --- a/frappe/test_runner.py +++ b/frappe/test_runner.py @@ -50,7 +50,7 @@ def main(app=None, module=None, doctype=None, verbose=False, tests=(), frappe.connect() # if not frappe.conf.get("db_name").startswith("test_"): - # raise Exception, 'db_name must start with "test_"' + # raise Exception, 'db_name must start with "test_"' # workaround! since there is no separate test db frappe.clear_cache() @@ -65,9 +65,9 @@ def main(app=None, module=None, doctype=None, verbose=False, tests=(), frappe.get_attr(fn)() if doctype: - ret = run_tests_for_doctype(doctype, verbose, tests, force, profile, junit_xml_output=junit_xml_output) + ret = run_tests_for_doctype(doctype, verbose, tests, force, profile, failfast=failfast, junit_xml_output=junit_xml_output) elif module: - ret = run_tests_for_module(module, verbose, tests, profile, junit_xml_output=junit_xml_output) + ret = run_tests_for_module(module, verbose, tests, profile, failfast=failfast, junit_xml_output=junit_xml_output) else: ret = run_all_tests(app, verbose, profile, ui_tests, failfast=failfast, junit_xml_output=junit_xml_output) @@ -150,7 +150,7 @@ def run_all_tests(app=None, verbose=False, profile=False, ui_tests=False, failfa return out -def run_tests_for_doctype(doctypes, verbose=False, tests=(), force=False, profile=False, junit_xml_output=False): +def run_tests_for_doctype(doctypes, verbose=False, tests=(), force=False, profile=False, failfast=False, junit_xml_output=False): modules = [] if not isinstance(doctypes, (list, tuple)): doctypes = [doctypes] @@ -168,18 +168,18 @@ def run_tests_for_doctype(doctypes, verbose=False, tests=(), force=False, profil make_test_records(doctype, verbose=verbose, force=force) modules.append(importlib.import_module(test_module)) - return _run_unittest(modules, verbose=verbose, tests=tests, profile=profile, junit_xml_output=junit_xml_output) + return _run_unittest(modules, verbose=verbose, tests=tests, profile=profile, failfast=failfast, junit_xml_output=junit_xml_output) -def run_tests_for_module(module, verbose=False, tests=(), profile=False, junit_xml_output=False): +def run_tests_for_module(module, verbose=False, tests=(), profile=False, failfast=False, junit_xml_output=False): module = importlib.import_module(module) if hasattr(module, "test_dependencies"): for doctype in module.test_dependencies: make_test_records(doctype, verbose=verbose) frappe.db.commit() - return _run_unittest(module, verbose=verbose, tests=tests, profile=profile, junit_xml_output=junit_xml_output) + return _run_unittest(module, verbose=verbose, tests=tests, profile=profile, failfast=failfast, junit_xml_output=junit_xml_output) -def _run_unittest(modules, verbose=False, tests=(), profile=False, junit_xml_output=False): +def _run_unittest(modules, verbose=False, tests=(), profile=False, failfast=False, junit_xml_output=False): frappe.db.begin() test_suite = unittest.TestSuite() @@ -198,9 +198,9 @@ def _run_unittest(modules, verbose=False, tests=(), profile=False, junit_xml_out test_suite.addTest(module_test_cases) if junit_xml_output: - runner = unittest_runner(verbosity=1+(verbose and 1 or 0)) + runner = unittest_runner(verbosity=1+(verbose and 1 or 0), failfast=failfast) else: - runner = unittest_runner(resultclass=TimeLoggingTestResult, verbosity=1+(verbose and 1 or 0)) + runner = unittest_runner(resultclass=TimeLoggingTestResult, verbosity=1+(verbose and 1 or 0), failfast=failfast) if profile: pr = cProfile.Profile()