猴子修补Odoo单元测试

2024-05-20 18:44:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一些定制的模块,它们改变了默认的工作流,因此必须重新编写相关的单元测试。首先,我在没有任何问题的情况下修补了一个crm模块单元测试。你知道吗

最初的crm单元测试:test_crm_ui.py on GitHub。你知道吗

自定义模块中的我的猴子补丁:

import odoo.addons.crm.tests.test_crm_ui

@odoo.tests.tagged('post_install', '-at_install')
class TestUi(odoo.addons.crm.tests.test_crm_ui.TestUi):
    def test_01_crm_tour(self):
        pass
        # ...

odoo.addons.crm.tests.test_crm_ui.TestUi = TestUi

哪个有效。

然后我需要对sale_mrp模块中的所有单元测试进行monkey补丁。test_multistep_manufacturing.py例如:original on GitHub。你知道吗

首先,我在下面尝试,类似于我对crm所做的。你知道吗

import odoo.addons.sale_mrp.tests.test_multistep_manufacturing

class ReplaceTestMultistepManufacturing(odoo.addons.sale_mrp.tests.test_multistep_manufacturing.TestMultistepManufacturing):
    def setUp(self):
        pass
        # ...
    def test_00_manufacturing_step_one(self):
        pass
        # ...

odoo.addons.sale_mrp.tests.test_multistep_manufacturing.TestMultistepManufacturing = ReplaceTestMultistepManufacturing

它确实不起作用,也许实际的模块并没有真正修补。然后我在下面试了试。你知道吗

from odoo.addons.sale_mrp.tests import test_multistep_manufacturing

class ReplaceTestMultistepManufacturing(test_multistep_manufacturing.TestMultistepManufacturing):
    def setUp(self):
        pass
        # ...
    def test_00_manufacturing_step_one(self):
        pass
        # ...

test_multistep_manufacturing.TestMultistepManufacturing = ReplaceTestMultistepManufacturing

也不起作用。实际上,两次尝试的结果是相同的—新测试和原始测试都运行了。你知道吗

我是做错了猴子补丁还是我需要做一些特别的奥多?谢谢!你知道吗


Tags: 模块odootestselfuidefmrptests