[IMP] runbot: improve test-tags support

The current post_install build mecanism is using extra params to give
test-tags. Unfortunately this disables the support for auto tags
and this have to be done manually. This means that auto tags are in the
build extra-params and not dynamic at rebuild of a post_install.

Also, using extraparams in the post install creation was removing
extra_params comming from custom trigger.

With this commit, the test-tags can be given inside config_data
and will be combined with config step test-tags and auto-tags.

This was an opportunity to simplify the logic.

This commit also fixes the test_install_tags that was broken.
This commit is contained in:
Xavier-Do 2023-04-04 14:33:49 +02:00 committed by Christophe Monniez
parent 2ad188201b
commit e3d87b5b5d
2 changed files with 53 additions and 34 deletions

View File

@ -435,25 +435,27 @@ class ConfigStep(models.Model):
cmd.extend(['--test-enable'])
else:
build._log('test_all', 'Installing modules without testing', level='WARNING')
test_tags_in_extra = '--test-tags' in extra_params
disable_auto_tags = build.params_id.config_data.get('disable_auto_tags', False)
if self.test_tags or test_tags_in_extra:
if "--test-tags" in available_options:
if not test_tags_in_extra:
test_tags = self.test_tags.replace(' ', '')
if self.enable_auto_tags and not disable_auto_tags:
auto_tags = self.env['runbot.build.error'].disabling_tags()
test_tags = ','.join(test_tags.split(',') + auto_tags)
cmd.extend(['--test-tags', test_tags])
else:
build._log('test_all', 'Test tags given but not supported')
elif self.enable_auto_tags and self.test_enable and not disable_auto_tags:
if grep(config_path, "[/module][:class]"):
auto_tags = self.env['runbot.build.error'].disabling_tags()
if auto_tags:
test_tags = ','.join(auto_tags)
cmd.extend(['--test-tags', test_tags])
if (self.test_enable or self.test_tags) and "--test-tags" in available_options and not test_tags_in_extra:
test_tags = []
custom_tags = build.params_id.config_data.get('test_tags')
if custom_tags:
test_tags += custom_tags.replace(' ', '').split(',')
if self.test_tags:
test_tags += self.test_tags.replace(' ', '').split(',')
if self.enable_auto_tags and not build.params_id.config_data.get('disable_auto_tags', False):
if grep(config_path, "[/module][:class]"):
auto_tags = self.env['runbot.build.error'].disabling_tags()
if auto_tags:
test_tags += auto_tags
test_tags = [test_tag for test_tag in test_tags if test_tag]
if test_tags:
cmd.extend(['--test-tags', ','.join(test_tags)])
elif test_tags_in_extra or self.test_tags and "--test-tags" not in available_options:
build._log('test_all', 'Test tags given but not supported')
if "--screenshots" in available_options:
cmd.add_config_tuple('screenshots', '/data/build/tests')

View File

@ -404,8 +404,15 @@ class TestBuildConfigStep(TestBuildConfigStepCommon):
config_step._run_install_odoo(self.parent_build, 'dev/null/logpath')
def get_test_tags(self, params):
cmds = params['cmd'].build().split(' && ')
self.assertEqual(cmds[1].split(' server/server.py')[0], 'python3')
return cmds[1].split('--test-tags ')[1].split(' ')[0]
@patch('odoo.addons.runbot.models.build.BuildResult.parse_config')
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_tags(self, mock_checkout):
def test_install_tags(self, mock_checkout, parse_config):
parse_config.return_value = {'--test-enable', '--test-tags'}
config_step = self.ConfigStep.create({
'name': 'all',
'job_type': 'install_odoo',
@ -417,26 +424,36 @@ class TestBuildConfigStep(TestBuildConfigStepCommon):
'random': True,
'test_tags': ':otherclass.othertest'
})
def docker_run(cmd, *args, **kwargs):
cmds = cmd.build().split(' && ')
self.assertEqual(cmds[1].split(' server/server.py')[0], 'python3')
tags = cmds[1].split('--test-tags ')[1].split(' ')[0]
self.assertEqual(tags, '/module,:class.method')
self.patchers['docker_run'].side_effect = docker_run
config_step._run_install_odoo(self.parent_build, 'dev/null/logpath')
params = config_step._run_install_odoo(self.parent_build, 'dev/null/logpath')
tags = self.get_test_tags(params)
self.assertEqual(tags, '/module,:class.method')
config_step.enable_auto_tags = True
params = config_step._run_install_odoo(self.parent_build, 'dev/null/logpath')
tags = self.get_test_tags(params)
self.assertEqual(tags, '/module,:class.method,-:otherclass.othertest')
def docker_run2(cmd, *args, **kwargs):
cmds = cmd.build().split(' && ')
self.assertEqual(cmds[1].split(' server/server.py')[0], 'python3')
tags = cmds[1].split('--test-tags ')[1].split(' ')[0]
self.assertEqual(tags, '/module,:class.method,-:otherclass.othertest')
@patch('odoo.addons.runbot.models.build.BuildResult.parse_config')
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_install_custom_tags(self, mock_checkout, parse_config):
parse_config.return_value = {'--test-enable', '--test-tags'}
config_step = self.ConfigStep.create({
'name': 'all',
'job_type': 'install_odoo',
'enable_auto_tags': True,
})
self.env['runbot.build.error'].create({
'content': 'foo',
'random': True,
'test_tags': ':otherclass.othertest'
})
child = self.parent_build._add_child({'config_data': {'test_tags': '-at_install,/module1,/module2'}})
params = config_step._run_install_odoo(child, 'dev/null/logpath')
tags = self.get_test_tags(params)
self.assertEqual(tags, '-at_install,/module1,/module2,-:otherclass.othertest')
self.patchers['docker_run'].side_effect = docker_run2
config_step._run_install_odoo(self.parent_build, 'dev/null/logpath')
@patch('odoo.addons.runbot.models.build.BuildResult._checkout')
def test_db_name(self, mock_checkout):