From c4e6f090b911e819a2753736125e6ac34efc361a Mon Sep 17 00:00:00 2001 From: Xavier-Do <xdo@odoo.com> Date: Fri, 7 Apr 2023 10:20:23 +0000 Subject: [PATCH] [FIX] tests: check test tags *_install 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#118042 Signed-off-by: Christophe Monniez (moc) <moc@odoo.com> --- addons/hr_org_chart/tests/test_employee_deletion.py | 2 +- addons/sms/tests/test_sms_template.py | 2 +- addons/survey/tests/test_survey_security.py | 2 +- odoo/addons/base/tests/test_tests_tags.py | 8 ++++---- odoo/tests/common.py | 4 ++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/addons/hr_org_chart/tests/test_employee_deletion.py b/addons/hr_org_chart/tests/test_employee_deletion.py index ba5fb329a822..be261fcfc829 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/sms/tests/test_sms_template.py b/addons/sms/tests/test_sms_template.py index 9483ecaf7bcf..132916667f15 100644 --- a/addons/sms/tests/test_sms_template.py +++ b/addons/sms/tests/test_sms_template.py @@ -8,7 +8,7 @@ from odoo.tests import tagged from odoo.tools import mute_logger -@tagged('post_install') +@tagged('post_install', '-at_install') class TestSmsTemplateAccessRights(SavepointCase): @classmethod diff --git a/addons/survey/tests/test_survey_security.py b/addons/survey/tests/test_survey_security.py index 191e8edd711b..27f974301bec 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/odoo/addons/base/tests/test_tests_tags.py b/odoo/addons/base/tests/test_tests_tags.py index 52856aadc83f..a823ee18ab26 100644 --- a/odoo/addons/base/tests/test_tests_tags.py +++ b/odoo/addons/base/tests/test_tests_tags.py @@ -89,19 +89,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'}) @tagged('nodatabase') diff --git a/odoo/tests/common.py b/odoo/tests/common.py index b5addb4533c5..0717a2e65ebf 100644 --- a/odoo/tests/common.py +++ b/odoo/tests/common.py @@ -2601,6 +2601,10 @@ def tagged(*tags): include = {t for t in tags if not t.startswith('-')} exclude = {t[1:] for t in tags if t.startswith('-')} obj.test_tags = (getattr(obj, 'test_tags', set()) | include) - exclude # todo remove getattr in master since we want to limmit tagged to BaseCase and always have +standard tag + 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 -- GitLab