From edff1295dee600bf7027e0066d76f546ceba2b24 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Fri, 5 Mar 2021 10:34:23 +0100 Subject: [PATCH] [IMP]Odoo shell helpers function signature improved --- odoo/odoo/shell_helpers.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/odoo/odoo/shell_helpers.py b/odoo/odoo/shell_helpers.py index 2d7c90c..c096bdb 100644 --- a/odoo/odoo/shell_helpers.py +++ b/odoo/odoo/shell_helpers.py @@ -20,21 +20,39 @@ from imp import reload import unittest -def run_test(module, test_names='ALL', test_class_name='DEFAULT'): +def run_test(module, test_names=False, test_class_name=''): """ Helper to allow testing of single method or all from TestCase Takes module as python module, and names as strings module is automatically reloaded for recent updates in shell test_names can be only one string or an array of strings - test_class_name can be automatically found from module name """ + test_class_name can be automatically found from module name. + + For example, from Odoo SHELL, first, import the modules : + + >>> from shell_helpers import run_test + >>> from odoo.addons.addon.tests import test_file + + Then, launch all tests from the module, and guessed className (here TestFile) : + + >>> run_test(test_file) + + Or launch only some tests : + + >>> run_test(test_file, ['test_one', 'test_two']) + + Or launch all tests from specific className : + + >>> run_test(test_file, test_class_name='TestModelOne') + """ module = reload(module) suite = unittest.TestSuite() - if test_class_name == 'DEFAULT': + if not test_class_name: module_name = module.__name__.split('.')[-1] test_class_name = ''.join(map(str.capitalize, module_name.split('_'))) if test_class_name not in dir(module): raise Exception('Generated class name (%s) not found in module, please ' 'specify' % test_class_name) - if test_names == 'ALL': + if not test_names: testCase = getattr(module, test_class_name) tests = unittest.TestLoader().loadTestsFromTestCase(testCase) suite.addTests(tests)