From 608c1ea10020cf02ea24b48c8fdb376c533b3517 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Fri, 7 Apr 2023 10:20:23 +0000 Subject: [PATCH] [FIX] tests: check test tags *_install MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Making a test post_install using @tagged should always remove the at_install tag. The main reason for that is that runbot split config select if an at_install or post_install tests should be executed is using negation: `--test-tags -post_install`. The reason for that is that giving a positive tag will replace the "standard" tag and non standard tag could be executed if giving `--test-tags at_install` (without negation) Since runbot tests in parallel builds, one of them using `--test-tags -post_install` and the other `--test-tags -at_install`, a test that is both post install and at install wont be executed at all. Also, a tests with both tags will be executed twice in a normal flow, usually not intended. The correct way to make a test post_install is to use @tagged('post_install', '-at_install') closes odoo/odoo#118969 X-original-commit: d1db306b212d4abb5b2faab9e56c8e83b85c53b9 Related: odoo/enterprise#39966 Signed-off-by: Christophe Monniez (moc) Signed-off-by: Xavier Dollé (xdo) --- addons/hr_org_chart/tests/test_employee_deletion.py | 2 +- addons/im_livechat/tests/test_digest.py | 2 +- addons/sms/tests/test_sms_template.py | 4 ++-- addons/survey/tests/test_survey_security.py | 2 +- addons/website_crm/tests/test_website_visitor.py | 2 -- odoo/addons/base/tests/test_tests_tags.py | 8 ++++---- odoo/tests/common.py | 5 +++++ 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/addons/hr_org_chart/tests/test_employee_deletion.py b/addons/hr_org_chart/tests/test_employee_deletion.py index ba5fb329a82..be261fcfc82 100644 --- a/addons/hr_org_chart/tests/test_employee_deletion.py +++ b/addons/hr_org_chart/tests/test_employee_deletion.py @@ -4,7 +4,7 @@ from odoo.tests import Form, tagged, TransactionCase from odoo.exceptions import MissingError -@tagged('post_install') +@tagged('post_install', '-at_install') class TestEmployeeDeletion(TransactionCase): def test_employee_deletion(self): diff --git a/addons/im_livechat/tests/test_digest.py b/addons/im_livechat/tests/test_digest.py index 2a6113df946..7340ffe5fac 100644 --- a/addons/im_livechat/tests/test_digest.py +++ b/addons/im_livechat/tests/test_digest.py @@ -6,7 +6,7 @@ from odoo.tools import mute_logger from odoo.tests import tagged -@tagged('post_install') +@tagged('post_install', '-at_install') class TestLiveChatDigest(TestDigestCommon): @classmethod diff --git a/addons/sms/tests/test_sms_template.py b/addons/sms/tests/test_sms_template.py index 20578723978..5802fd62cd6 100644 --- a/addons/sms/tests/test_sms_template.py +++ b/addons/sms/tests/test_sms_template.py @@ -10,7 +10,7 @@ from odoo.tools import mute_logger, convert_file from odoo.modules.module import get_module_resource -@tagged('post_install') +@tagged('post_install', '-at_install') class TestSmsTemplateAccessRights(TransactionCase): @classmethod @@ -110,7 +110,7 @@ class TestSmsTemplateAccessRights(TransactionCase): self.assertIn(self.partner.name, body, 'Template Editor should be able to write new Jinja code') -@tagged('post_install') +@tagged('post_install', '-at_install') class TestSMSTemplateReset(TransactionCase): def _load(self, module, *args): diff --git a/addons/survey/tests/test_survey_security.py b/addons/survey/tests/test_survey_security.py index 517d4f43501..7db5ddceaf5 100644 --- a/addons/survey/tests/test_survey_security.py +++ b/addons/survey/tests/test_survey_security.py @@ -326,7 +326,7 @@ class TestAccess(common.TestSurveyCommon): (answer_own | answer_other | self.answer_0).unlink() -@tagged('post_install') +@tagged('post_install', '-at_install') class TestSurveySecurityControllers(common.TestSurveyCommon, HttpCase): def test_survey_start_short(self): # avoid name clash with existing data diff --git a/addons/website_crm/tests/test_website_visitor.py b/addons/website_crm/tests/test_website_visitor.py index c537cc63155..052225fbba2 100644 --- a/addons/website_crm/tests/test_website_visitor.py +++ b/addons/website_crm/tests/test_website_visitor.py @@ -71,7 +71,6 @@ class TestWebsiteVisitor(TestCrmCommon, WebsiteVisitorTests): self.assertEqual(visitor.email, customer.email_normalized) self.assertEqual(visitor.mobile, lead_2.mobile) - @tagged('website_visitor') def test_clean_inactive_visitors_crm(self): """ Visitors attached to leads should not be deleted even if not connected recently. """ active_visitors = self.env['website.visitor'].create([{ @@ -87,7 +86,6 @@ class TestWebsiteVisitor(TestCrmCommon, WebsiteVisitorTests): self._test_unlink_old_visitors(self.env['website.visitor'], active_visitors) - @tagged('website_visitor') def test_link_to_visitor_crm(self): """ Same as parent's 'test_link_to_visitor' except we also test that leads are merged into main visitor. """ diff --git a/odoo/addons/base/tests/test_tests_tags.py b/odoo/addons/base/tests/test_tests_tags.py index 59080ac4aea..d6cfdd14c11 100644 --- a/odoo/addons/base/tests/test_tests_tags.py +++ b/odoo/addons/base/tests/test_tests_tags.py @@ -88,19 +88,19 @@ class TestSetTags(TransactionCase): self.assertEqual(fc.test_tags, {'at_install'}) self.assertEqual(fc.test_module, 'base') - @tagged('-standard', '-base', '-at_install') + @tagged('-standard', '-base', '-at_install', 'post_install') class FakeClassB(TransactionCase): pass fc = FakeClassB() - self.assertEqual(fc.test_tags, set()) + self.assertEqual(fc.test_tags, {'post_install'}) - @tagged('-standard', '-base', '-at_install', 'fast') + @tagged('-standard', '-base', 'fast') class FakeClassC(TransactionCase): pass fc = FakeClassC() - self.assertEqual(fc.test_tags, {'fast', }) + self.assertEqual(fc.test_tags, {'fast', 'at_install'}) def test_parental_advisory(self): """Explicit test tags on the class should override anything diff --git a/odoo/tests/common.py b/odoo/tests/common.py index af909161de5..95dc3c5630f 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -1875,7 +1875,12 @@ def tagged(*tags): """ include = {t for t in tags if not t.startswith('-')} exclude = {t[1:] for t in tags if t.startswith('-')} + def tags_decorator(obj): obj.test_tags = (getattr(obj, 'test_tags', set()) | include) - exclude + at_install = 'at_install' in obj.test_tags + post_install = 'post_install' in obj.test_tags + if not (at_install ^ post_install): + _logger.warning('A tests should be either at_install or post_install, which is not the case of %r', obj) return obj return tags_decorator