odoo12下可行,其它版本未測(cè)試
# 添加引用
from odoo.tools import config
# 隨便在哪個(gè)model里面添加這個(gè)方法,然后在系統(tǒng)后臺(tái)計(jì)劃任務(wù)里面調(diào)用即可
# env['ir.cron'].run_tests('yumtown_account', 'odoo_test')
@api.model
def run_tests(self, module_name, dbname):
config['test_tags'] = module_name
config['test_enable'] = True
odoo.modules.module.run_unit_tests(module_name, self.env.cr.dbname, 'post_install')