summaryrefslogtreecommitdiff
path: root/odoo/modules/module.py
diff options
context:
space:
mode:
authorChristophe Monniez <moc@odoo.com>2017-08-21 08:36:35 +0200
committerChristophe Monniez <moc@odoo.com>2018-01-18 13:20:37 +0100
commitb356b190338e3ee032b9e3a7f670f76468965006 (patch)
treef32b334a7a7a467646e778d9f93a70a262f5b626 /odoo/modules/module.py
parent079e1a0c312ea6ed66ed42676b25b6ac22db2b58 (diff)
[IMP] tests: Add the possibility to tag tests
Purpose: When running tests, all the tests for the installed/updated files are done. This commit adds a 'tagged' decorator that can be used to tag tests. Combined with a new 'test-tags' CLI option, it adds the ability to filter which tests are executed. For example, @tagged('slow') will add a tag 'slow' to the test. The CLI option 'test-tags="slow"' will only run tests tagged 'slow'. One can use prefixes to select cases with tags. '+' or no prefix means that the tests tagged with this tag are selected for execution. '-' prefix will exclude the tests tagged with this tag. Exclusion takes precedence over inclusion. Also, by default, all Odoo tests cases are tagged 'standard' and with the technical name of the module. This means that when selecting tests with the 'test-tags' parameter, if '-standard' is not specified, all tests tags are going to be executed. When tagging tests, one can remove such automatic tag by prefixing the tag name with '-'. E.g. @tagged('-standard') will remove the standard tag from the test. Another example, if one wants to test the 'sale' module alone, even without adding any 'tagged' decorator thos tests can be selected like that: --test-tags="sale" Tests are selected or deselected using a TagsSelector. When instanciated, a string is passed with comma separated tests selectors like '+slow,-standard'. When the 'check' method is called with a test as argument, it returns True or False if the test has to be executed or not.
Diffstat (limited to 'odoo/modules/module.py')
-rw-r--r--odoo/modules/module.py23
1 files changed, 5 insertions, 18 deletions
diff --git a/odoo/modules/module.py b/odoo/modules/module.py
index 15f4aae9a50..d92e2fbf6d6 100644
--- a/odoo/modules/module.py
+++ b/odoo/modules/module.py
@@ -475,36 +475,23 @@ class TestStream(object):
current_test = None
-def runs_at(test, hook, default):
- # by default, tests do not run post install
- test_runs = getattr(test, hook, default)
-
- # for a test suite, we're done
- if not isinstance(test, unittest.TestCase):
- return test_runs
-
- # otherwise check the current test method to see it's been set to a
- # different state
- method = getattr(test, test._testMethodName)
- return getattr(method, hook, test_runs)
-
-runs_at_install = functools.partial(runs_at, hook='at_install', default=True)
-runs_post_install = functools.partial(runs_at, hook='post_install', default=False)
-
-def run_unit_tests(module_name, dbname, position=runs_at_install):
+def run_unit_tests(module_name, dbname, position='at_install'):
"""
:returns: ``True`` if all of ``module_name``'s tests succeeded, ``False``
if any of them failed.
:rtype: bool
"""
global current_test
+ from odoo.tests.common import TagsSelector # Avoid import loop
current_test = module_name
mods = get_test_modules(module_name)
threading.currentThread().testing = True
+ config_tags = TagsSelector(tools.config['test_tags'])
+ position_tag = TagsSelector(position)
r = True
for m in mods:
tests = unwrap_suite(unittest.TestLoader().loadTestsFromModule(m))
- suite = unittest.TestSuite(t for t in tests if position(t))
+ suite = unittest.TestSuite(t for t in tests if position_tag.check(t) and config_tags.check(t))
if suite.countTestCases():
t0 = time.time()