enhance(testing): allow tests to be run by skipping fixtures with --skip-before-tests and --skip-test-records

This commit is contained in:
Rushabh Mehta 2018-08-31 15:30:30 +05:30
parent ef67b9265b
commit 2a8e890fee
2 changed files with 17 additions and 6 deletions

View file

@ -374,10 +374,13 @@ def console(context):
@click.option('--ui-tests', is_flag=True, default=False, help="Run UI Tests")
@click.option('--module', help="Run tests in a module")
@click.option('--profile', is_flag=True, default=False)
@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")
@pass_context
def run_tests(context, app=None, module=None, doctype=None, test=(),
driver=None, profile=False, junit_xml_output=False, ui_tests = False, doctype_list_path=None):
driver=None, profile=False, junit_xml_output=False, ui_tests = False,
doctype_list_path=None, skip_test_records=False, skip_before_tests=False):
"Run tests"
import frappe.test_runner
tests = test
@ -385,6 +388,9 @@ def run_tests(context, app=None, module=None, doctype=None, test=(),
site = get_site(context)
frappe.init(site=site)
frappe.flags.skip_before_tests = skip_before_tests
frappe.flags.skip_test_records = skip_test_records
ret = frappe.test_runner.main(app, module, doctype, context.verbose, tests=tests,
force=context.force, profile=profile, junit_xml_output=junit_xml_output,
ui_tests = ui_tests, doctype_list_path = doctype_list_path)

View file

@ -25,7 +25,8 @@ def xmlrunner_wrapper(output):
return _runner
def main(app=None, module=None, doctype=None, verbose=False, tests=(),
force=False, profile=False, junit_xml_output=None, ui_tests=False, doctype_list_path=None):
force=False, profile=False, junit_xml_output=None, ui_tests=False,
doctype_list_path=None, skip_test_records=False):
global unittest_runner
if doctype_list_path:
@ -55,10 +56,11 @@ def main(app=None, module=None, doctype=None, verbose=False, tests=(),
frappe.utils.scheduler.disable_scheduler()
set_test_email_config()
if verbose:
print('Running "before_tests" hooks')
for fn in frappe.get_hooks("before_tests", app_name=app):
frappe.get_attr(fn)()
if not frappe.flags.skip_before_tests:
if verbose:
print('Running "before_tests" hooks')
for fn in frappe.get_hooks("before_tests", app_name=app):
frappe.get_attr(fn)()
if doctype:
ret = run_tests_for_doctype(doctype, verbose, tests, force, profile)
@ -243,6 +245,9 @@ def make_test_records(doctype, verbose=0, force=False):
if not frappe.db:
frappe.connect()
if frappe.flags.skip_test_records:
return
for options in get_dependencies(doctype):
if options == "[Select]":
continue