odoo12下可行,其它版本未測試
# 添加引用
from odoo.tools import config
# 隨便在哪個model里面添加這個方法,然后在系統后臺計劃任務里面調用即可
# 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')