Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test-list option to run-ui-tests #4540

Merged
merged 2 commits into from
Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions frappe/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,18 @@ def run_tests(context, app=None, module=None, doctype=None, test=(),
@click.command('run-ui-tests')
@click.option('--app', help="App to run tests on, leave blank for all apps")
@click.option('--test', help="Path to the specific test you want to run")
@click.option('--test-list', help="Path to the txt file with the list of test cases")
@click.option('--profile', is_flag=True, default=False)
@pass_context
def run_ui_tests(context, app=None, test=False, profile=False):
def run_ui_tests(context, app=None, test=False, test_list=False, profile=False):
"Run UI tests"
import frappe.test_runner

site = get_site(context)
frappe.init(site=site)
frappe.connect()

ret = frappe.test_runner.run_ui_tests(app=app, test=test, verbose=context.verbose,
ret = frappe.test_runner.run_ui_tests(app=app, test=test, test_list=test_list, verbose=context.verbose,
profile=profile)
if len(ret.failures) == 0 and len(ret.errors) == 0:
ret = 0
Expand Down
9 changes: 6 additions & 3 deletions frappe/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,16 @@ def run_tests_for_module(module, verbose=False, tests=(), profile=False):
def run_setup_wizard_ui_test(app=None, verbose=False, profile=False):
'''Run setup wizard UI test using test_test_runner'''
frappe.flags.run_setup_wizard_ui_test = 1
return run_ui_tests(app, None, verbose, profile)
return run_ui_tests(app=app, test=None, verbose=verbose, profile=profile)

def run_ui_tests(app=None, test=None, verbose=False, profile=False):
def run_ui_tests(app=None, test=None, test_list=None, verbose=False, profile=False):
'''Run a single unit test for UI using test_test_runner'''
module = importlib.import_module('frappe.tests.ui.test_test_runner')
frappe.flags.ui_test_app = app
frappe.flags.ui_test_path = test
if test_list:
frappe.flags.ui_test_list = test_list
else:
frappe.flags.ui_test_path = test
return _run_unittest(module=module, verbose=verbose, tests=(), profile=profile)

def _run_unittest(module, verbose=False, tests=(), profile=False):
Expand Down
16 changes: 12 additions & 4 deletions frappe/tests/ui/test_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def get_tests():
'''Get tests base on flag'''
frappe.db.set_value('Test Runner', None, 'app', frappe.flags.ui_test_app or '')

if frappe.flags.ui_test_path:
if frappe.flags.ui_test_list:
# list of tests
return get_tests_for(test_list=frappe.flags.ui_test_list)
elif frappe.flags.ui_test_path:
# specific test
return (frappe.flags.ui_test_path,)
elif frappe.flags.ui_test_app:
Expand All @@ -64,10 +67,15 @@ def get_tests():
tests.extend(get_tests_for(app))
return tests

def get_tests_for(app):
'''Get all tests for a particular app'''
def get_tests_for(app=None, test_list=None):
tests = []
tests_path = frappe.get_app_path(app, 'tests', 'ui', 'tests.txt')
if test_list:
# Get all tests from a particular txt file
app, test_list = test_list.split(os.path.sep, 1)
tests_path = frappe.get_app_path(app, test_list)
else:
# Get all tests for a particular app
tests_path = frappe.get_app_path(app, 'tests', 'ui', 'tests.txt')
if os.path.exists(tests_path):
with open(tests_path, 'r') as fileobj:
tests = fileobj.read().strip().splitlines()
Expand Down