Skip to content

Commit 482cb08

Browse files
committed
[FIX] base: allow patching of config.options for 3.11
Since python/cpython#18544, unittest mock is not able to properly find the "odoo.tools.config". When trying to patch the `options` dictionnary, it leads to `AttributeError: module 'odoo.tools.config' has no attribute 'options'` In order to have the tests working in python <= 3.11, we have to import the config module and patch the options in place. Part-of: #112317
1 parent 5d90802 commit 482cb08

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

odoo/addons/base/tests/test_ir_mail_server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from odoo.tests import tagged
1010
from odoo.tests.common import TransactionCase
1111
from odoo.tools import mute_logger
12+
from odoo.tools import config
1213

1314

1415
@tagged('mail_server')
@@ -337,7 +338,7 @@ def test_mail_server_send_email_smtp_session(self):
337338
)
338339

339340
@mute_logger('odoo.models.unlink')
340-
@patch.dict("odoo.tools.config.options", {"from_filter": "test.com", "smtp_server": "example.com"})
341+
@patch.dict(config.options, {"from_filter": "test.com", "smtp_server": "example.com"})
341342
def test_mail_server_binary_arguments_domain(self):
342343
"""Test the configuration provided in the odoo-bin arguments.
343344
@@ -389,7 +390,7 @@ def test_mail_server_binary_arguments_domain(self):
389390
)
390391

391392
@mute_logger('odoo.models.unlink')
392-
@patch.dict("odoo.tools.config.options", {"from_filter": "test.com", "smtp_server": "example.com"})
393+
@patch.dict(config.options, {"from_filter": "test.com", "smtp_server": "example.com"})
393394
def test_mail_server_binary_arguments_domain_smtp_session(self):
394395
"""Test the configuration provided in the odoo-bin arguments.
395396
@@ -432,7 +433,7 @@ def test_mail_server_binary_arguments_domain_smtp_session(self):
432433
)
433434

434435
@mute_logger('odoo.models.unlink')
435-
@patch.dict('odoo.tools.config.options', {'from_filter': 'test.com', 'smtp_server': 'example.com'})
436+
@patch.dict(config.options, {'from_filter': 'test.com', 'smtp_server': 'example.com'})
436437
def test_mail_server_mail_default_from_filter(self):
437438
"""Test that the config parameter "mail.default.from_filter" overwrite the odoo-bin
438439
argument "--from-filter"

odoo/addons/base/tests/test_mail.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
email_split, email_domain_normalize,
1616
misc, formataddr,
1717
prepend_html_content,
18+
config,
1819
)
1920

2021
from . import test_mail_examples
@@ -465,7 +466,7 @@ def test_email_domain_normalize(self):
465466

466467

467468
class EmailConfigCase(TransactionCase):
468-
@patch.dict("odoo.tools.config.options", {"email_from": "settings@example.com"})
469+
@patch.dict(config.options, {"email_from": "settings@example.com"})
469470
def test_default_email_from(self, *args):
470471
"""Email from setting is respected."""
471472
# ICP setting is more important

0 commit comments

Comments
 (0)