Use regex to check if test belong to test set
When discovering available tests regular expression will be used to check to which test set given test belongs. This prevent situation when 'test_sanity_sahara' was assigned to 'ha' test set because of occurrence of this words in 'sahara' Change-Id: If7366da29da17404af3564e031e47e7ab39ba826 Closes-Bug: #1359728
This commit is contained in:
parent
47b82d5130
commit
70ecf3b93c
|
@ -14,6 +14,7 @@
|
|||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
from nose import plugins
|
||||
|
||||
|
@ -68,10 +69,18 @@ class DiscoveryPlugin(plugins.Plugin):
|
|||
)
|
||||
LOG.info('%s discovered.', module.__name__)
|
||||
|
||||
@classmethod
|
||||
def test_belongs_to_testset(cls, test_id, test_set_id):
|
||||
"""Checks by name if test belongs to given test set."""
|
||||
test_set_pattern = re.compile(
|
||||
r'(\b|_){0}(\b|_)'.format(test_set_id)
|
||||
)
|
||||
return bool(test_set_pattern.search(test_id))
|
||||
|
||||
def addSuccess(self, test):
|
||||
test_id = test.id()
|
||||
for test_set_id in self.test_sets.keys():
|
||||
if test_set_id in test_id:
|
||||
if self.test_belongs_to_testset(test_id, test_set_id):
|
||||
data = dict()
|
||||
|
||||
(data['title'], data['description'],
|
||||
|
|
|
@ -131,3 +131,29 @@ class TestNoseDiscovery(base.BaseUnitTest):
|
|||
needed_test.deployment_tags,
|
||||
expected['test']['deployment_tags']
|
||||
)
|
||||
|
||||
def test_if_test_belongs_to_test_set(self):
|
||||
test_set_id = 'ha'
|
||||
pass_checks = (
|
||||
'test_ha_sth',
|
||||
'test-ha-ha',
|
||||
'test.ha.sahara',
|
||||
'test.ha.sth',
|
||||
)
|
||||
fail_checks = (
|
||||
'test_sahara',
|
||||
'test.nonha.sth',
|
||||
'test.nonha.sahara',
|
||||
)
|
||||
|
||||
for test_id in pass_checks:
|
||||
self.assertTrue(
|
||||
nose_discovery.DiscoveryPlugin.test_belongs_to_testset(
|
||||
test_id, test_set_id)
|
||||
)
|
||||
|
||||
for test_id in fail_checks:
|
||||
self.assertFalse(
|
||||
nose_discovery.DiscoveryPlugin.test_belongs_to_testset(
|
||||
test_id, test_set_id)
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue