From 554eeae329dbaca9a3caf7ba7fc93adc64da93b3 Mon Sep 17 00:00:00 2001 From: josep-tecnativa Date: Tue, 24 Oct 2023 09:43:42 +0200 Subject: [PATCH] [IMP] report_xlsx: test performance improvement - Switch to setUpClass for avoiding repeat the same setup for each test. - Include context keys for avoiding mail operations overhead. --- report_xlsx/tests/test_report.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/report_xlsx/tests/test_report.py b/report_xlsx/tests/test_report.py index a254294b1..43026597e 100644 --- a/report_xlsx/tests/test_report.py +++ b/report_xlsx/tests/test_report.py @@ -14,15 +14,26 @@ except ImportError: class TestReport(common.TransactionCase): - def setUp(self): - super().setUp() - report_object = self.env["ir.actions.report"] - self.xlsx_report = self.env["report.report_xlsx.abstract"].with_context( + @classmethod + def setUpClass(cls): + super().setUpClass() + # Remove this variable in v16 and put instead: + # from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT + DISABLED_MAIL_CONTEXT = { + "tracking_disable": True, + "mail_create_nolog": True, + "mail_create_nosubscribe": True, + "mail_notrack": True, + "no_reset_password": True, + } + cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT)) + report_object = cls.env["ir.actions.report"] + cls.xlsx_report = cls.env["report.report_xlsx.abstract"].with_context( active_model="res.partner" ) - self.report_name = "report_xlsx.partner_xlsx" - self.report = report_object._get_report_from_name(self.report_name) - self.docs = self.env["res.company"].search([], limit=1).partner_id + cls.report_name = "report_xlsx.partner_xlsx" + cls.report = report_object._get_report_from_name(cls.report_name) + cls.docs = cls.env["res.company"].search([], limit=1).partner_id def test_report(self): report = self.report