Skip to content

Commit

Permalink
[IMP] component: test performance improvement
Browse files Browse the repository at this point in the history
- Switch to setUpClass (if needed) for avoiding repeat the same setup for each test.
- Include context keys for avoiding mail operations overhead.
  • Loading branch information
josep-tecnativa committed Oct 20, 2023
1 parent 4b5c93b commit 9835126
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion component/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from odoo import api
from odoo.tests import common

from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
from odoo.addons.component.core import ComponentRegistry, MetaComponent, _get_addon_name


Expand Down Expand Up @@ -67,6 +68,7 @@ class TransactionComponentCase(common.TransactionCase, ComponentMixin):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.setUpComponent()

# pylint: disable=W8106
Expand Down Expand Up @@ -208,5 +210,17 @@ def tearDownClass(cls):
# pylint: disable=W8106
@classmethod
def setUpClass(cls):
super().setUpClass()
# resolve an inheritance issue (common.TransactionCase does not use
# super)
common.TransactionCase.setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.collection = cls.env["collection.base"]

0 comments on commit 9835126

Please sign in to comment.