Bläddra i källkod

[enhance] bench run-tests --doctype-list app/path/to/test.txt (#4561)

* [enhance] bench run-tests --doctype-list app/path/to/test.txt

* [fix] tests for doctype-list-path

* [fix] tests for doctype-list-path
version-14
Rushabh Mehta 7 år sedan
committed by GitHub
förälder
incheckning
5a9d38f767
Ingen känd nyckel hittad för denna signaturen i databasen GPG-nyckel ID: 4AEE18F83AFDEB23
3 ändrade filer med 46 tillägg och 29 borttagningar
  1. +3
    -2
      frappe/commands/utils.py
  2. +1
    -1
      frappe/desk/page/setup_wizard/setup_wizard.js
  3. +42
    -26
      frappe/test_runner.py

+ 3
- 2
frappe/commands/utils.py Visa fil

@@ -300,6 +300,7 @@ def console(context):
@click.command('run-tests')
@click.option('--app', help="For App")
@click.option('--doctype', help="For DocType")
@click.option('--doctype-list-path', help="Path to .txt file for list of doctypes. Example erpnext/tests/server/agriculture.txt")
@click.option('--test', multiple=True, help="Specific test")
@click.option('--driver', help="For Travis")
@click.option('--ui-tests', is_flag=True, default=False, help="Run UI Tests")
@@ -308,7 +309,7 @@ def console(context):
@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):
driver=None, profile=False, junit_xml_output=False, ui_tests = False, doctype_list_path=None):
"Run tests"
import frappe.test_runner
tests = test
@@ -318,7 +319,7 @@ def run_tests(context, app=None, module=None, doctype=None, test=(),

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)
ui_tests = ui_tests, doctype_list_path = doctype_list_path)
if len(ret.failures) == 0 and len(ret.errors) == 0:
ret = 0



+ 1
- 1
frappe/desk/page/setup_wizard/setup_wizard.js Visa fil

@@ -244,7 +244,7 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides {
this.current_slide = null;
this.completed_state_message = this.get_message(
__("Setup Complete"),
__("You're all set!")
__("Refreshing...")
);
}



+ 42
- 26
frappe/test_runner.py Visa fil

@@ -4,7 +4,7 @@
from __future__ import unicode_literals, print_function

import frappe
import unittest, json, sys
import unittest, json, sys, os
import xmlrunner
import importlib
from frappe.modules import load_doctype_module, get_module_name
@@ -25,9 +25,14 @@ 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):
force=False, profile=False, junit_xml_output=None, ui_tests=False, doctype_list_path=None):
global unittest_runner

if doctype_list_path:
app, doctype_list_path = doctype_list_path.split(os.path.sep, 1)
with open(frappe.get_app_path(app, doctype_list_path), 'r') as f:
doctype = f.read().strip().splitlines()

xmloutput_fh = None
if junit_xml_output:
xmloutput_fh = open(junit_xml_output, 'w')
@@ -119,19 +124,25 @@ def run_all_tests(app=None, verbose=False, profile=False, ui_tests=False):

return out

def run_tests_for_doctype(doctype, verbose=False, tests=(), force=False, profile=False):
module = frappe.db.get_value("DocType", doctype, "module")
if not module:
print('Invalid doctype {0}'.format(doctype))
sys.exit(1)

test_module = get_module_name(doctype, module, "test_")
if force:
for name in frappe.db.sql_list("select name from `tab%s`" % doctype):
frappe.delete_doc(doctype, name, force=True)
make_test_records(doctype, verbose=verbose, force=force)
module = importlib.import_module(test_module)
return _run_unittest(module, verbose=verbose, tests=tests, profile=profile)
def run_tests_for_doctype(doctypes, verbose=False, tests=(), force=False, profile=False):
modules = []
if not isinstance(doctypes, (list, tuple)):
doctypes = [doctypes]

for doctype in doctypes:
module = frappe.db.get_value("DocType", doctype, "module")
if not module:
print('Invalid doctype {0}'.format(doctype))
sys.exit(1)

test_module = get_module_name(doctype, module, "test_")
if force:
for name in frappe.db.sql_list("select name from `tab%s`" % doctype):
frappe.delete_doc(doctype, name, force=True)
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)

def run_tests_for_module(module, verbose=False, tests=(), profile=False):
module = importlib.import_module(module)
@@ -139,7 +150,7 @@ def run_tests_for_module(module, verbose=False, tests=(), profile=False):
for doctype in module.test_dependencies:
make_test_records(doctype, verbose=verbose)

return _run_unittest(module=module, verbose=verbose, tests=tests, profile=profile)
return _run_unittest(module, verbose=verbose, tests=tests, profile=profile)

def run_setup_wizard_ui_test(app=None, verbose=False, profile=False):
'''Run setup wizard UI test using test_test_runner'''
@@ -154,18 +165,23 @@ def run_ui_tests(app=None, test=None, test_list=None, verbose=False, profile=Fal
frappe.flags.ui_test_list = test_list
else:
frappe.flags.ui_test_path = test
return _run_unittest(module=module, verbose=verbose, tests=(), profile=profile)
return _run_unittest(module, verbose=verbose, tests=(), profile=profile)

def _run_unittest(module, verbose=False, tests=(), profile=False):
def _run_unittest(modules, verbose=False, tests=(), profile=False):
test_suite = unittest.TestSuite()
module_test_cases = unittest.TestLoader().loadTestsFromModule(module)
if tests:
for each in module_test_cases:
for test_case in each.__dict__["_tests"]:
if test_case.__dict__["_testMethodName"] in tests:
test_suite.addTest(test_case)
else:
test_suite.addTest(module_test_cases)

if not isinstance(modules, (list, tuple)):
modules = [modules]

for module in modules:
module_test_cases = unittest.TestLoader().loadTestsFromModule(module)
if tests:
for each in module_test_cases:
for test_case in each.__dict__["_tests"]:
if test_case.__dict__["_testMethodName"] in tests:
test_suite.addTest(test_case)
else:
test_suite.addTest(module_test_cases)

if profile:
pr = cProfile.Profile()


Laddar…
Avbryt
Spara