Handle overlapping black regexes
It's very common for blacklist files and/or a black regex to have overlapping matches. In this case ostestr was incorrectly trying to remove tests from the set of test cases more than once. This commit fixes this case by simply adding a check if the test is in the set before trying to delete it. If it's not there, then something else already removed it from the set of tests we'll be running so we can just move on. Change-Id: I1dabf9fb9c182af3dd6e124e79e54e1eb99bed82
This commit is contained in:
parent
158b2506b7
commit
3acc96e47a
@ -94,6 +94,9 @@ def construct_list(blacklist_file, whitelist_file, regex, black_regex,
|
|||||||
for (rex, msg, s_list) in black_data:
|
for (rex, msg, s_list) in black_data:
|
||||||
for test_case in list_of_test_cases:
|
for test_case in list_of_test_cases:
|
||||||
if rex.search(test_case):
|
if rex.search(test_case):
|
||||||
|
# NOTE(mtreinish): In the case of overlapping regex the test
|
||||||
|
# case might have already been removed from the set of tests
|
||||||
|
if test_case in set_of_test_cases:
|
||||||
set_of_test_cases.remove(test_case)
|
set_of_test_cases.remove(test_case)
|
||||||
s_list.append(test_case)
|
s_list.append(test_case)
|
||||||
|
|
||||||
|
@ -114,3 +114,25 @@ class TestConstructList(base.TestCase):
|
|||||||
False)
|
False)
|
||||||
self.assertEqual(set(result),
|
self.assertEqual(set(result),
|
||||||
set(('fake_test1[tg]', 'fake_test3[tg,foo]')))
|
set(('fake_test1[tg]', 'fake_test3[tg,foo]')))
|
||||||
|
|
||||||
|
def test_overlapping_black_regex(self):
|
||||||
|
|
||||||
|
black_list = [(re.compile('compute.test_keypairs.KeypairsTestV210'),
|
||||||
|
'', []),
|
||||||
|
(re.compile('compute.test_keypairs.KeypairsTestV21'),
|
||||||
|
'', [])]
|
||||||
|
test_lists = [
|
||||||
|
'compute.test_keypairs.KeypairsTestV210.test_create_keypair',
|
||||||
|
'compute.test_keypairs.KeypairsTestV21.test_create_keypair',
|
||||||
|
'compute.test_fake.FakeTest.test_fake_test']
|
||||||
|
with mock.patch('os_testr.regex_builder._get_test_list',
|
||||||
|
return_value=test_lists):
|
||||||
|
with mock.patch('os_testr.testlist_builder.black_reader',
|
||||||
|
return_value=black_list):
|
||||||
|
result = list_builder.construct_list('file',
|
||||||
|
None,
|
||||||
|
'fake_test',
|
||||||
|
None,
|
||||||
|
False)
|
||||||
|
self.assertEqual(
|
||||||
|
list(result), ['compute.test_fake.FakeTest.test_fake_test'])
|
||||||
|
Loading…
Reference in New Issue
Block a user