admin管理员组文章数量:1391943
In odoo 17 I need to use unitest.mock to mock the return value of a function The function is called cfdi_cancel. It is located in mymodulename module, inside that module is the 'models' folder, inside that folder is the 'pac_utils' python file, and inside that file is the cfdi_cancel function I am getting the following error
File "/usr/lib/python3.10/unittest/mock.py", line 1257, in _importer
thing = __import__(import_path)
ModuleNotFoundError: No module named 'mymodulename'
So, the question is: How can I use unittest.mock to set a return value for that function?
This is my code
from unittest.mock import patch, MagicMock
class TestViixooCFDICancelPayslip(TestPayroll):
@classmethod
def setUpClass(cls):
super(TestViixooCFDICancelPayslip, cls).setUpClass()
cls.payslip.cfdi_uuid = "12345-UUID"
cls.payslip.cfdi_state = "sent"
cls.payslip.cfdi_substituted_payslip_id = None
@patch("mymodulename.models.pac_utils.cfdi_cancel") # Mock the external cancellation function
def test_cfdi_cancel_payslip_success(self, mock_cfdi_cancel):
mock_cfdi_cancel.return_value = {}
self.payslip.cfdi_cancel_payslip("01")
mock_cfdi_cancel.assert_called_once_with(
context=self.payslip,
uuid="12345-UUID",
cancel_reason="01",
cancel_uuid=None,
)
self.assertEqual(self.payslip.cfdi_state, "cancelled")
本文标签: Using unittestMock in Odoo 17Stack Overflow
版权声明:本文标题:Using unittest.Mock in Odoo 17 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744683528a2619560.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论