2

I have some customized modules which change the default workflow, thus have to re-write related unit tests. First, I monkey patched one crm module unit test without any issue.

The original crm unit test: test_crm_ui.py on GitHub.

My monkey patch in a customized module:

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

Which worked.

Then I need to monkey patch all unit tests in sale_mrp module. test_multistep_manufacturing.py for example: original on GitHub.

First I tried below, similar to what I did to 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

Which did not work, maybe the actual module was not really patched. Then I tried below.

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

Which also did not work. Actually two attempts resulted the same - both the new test and the original test was run.

Am I doing monkey patch wrong or I need to do something special in Odoo? Thanks!

mingtwo_h9
  • 316
  • 1
  • 7
  • 2
    check again may be you miss spell some variable because It should work, but I didn't see any class named `TestMultistepManufacturing` In odoo github code!!! – Charif DZ Jun 30 '19 at 07:15
  • @EasyOdoo My apologies... ```TestMultistepManufacturing``` was in ```test_multistep_manufacturing.py```, was too tired last night and didn't notice I put the wrong info. I have updated the question and link. I feel the original test is already doing monkey patch to ```TestMrpCommon```, is it okay to monkey patch a monkey patch? – mingtwo_h9 Jun 30 '19 at 11:49
  • I don't think is monkey patching it's like duplicating the test, and adding new ones. from the way I see it. really don't know what will happen when you declare a new class that inherit a class is it overriding, or duplicating or just adding didn't think about that – Charif DZ Jun 30 '19 at 21:16

0 Answers0