200
class TestIdList(object):
201
"""Test id list to filter a test suite.
203
Relying on the assumption that test ids are built as:
204
<module>[.<class>.<method>][(<param>+)], <module> being in python dotted
205
notation, this class offers methods to :
206
- keep only the listed tests from a given suite.
209
def __init__(self, test_id_list):
210
# When a test suite needs to be filtered against us we compare test ids
211
# for strict equality, so a simple dict offers a quick and simple
213
self.tests = dict().fromkeys(test_id_list, True)
215
def includes(self, test_id):
216
return test_id in self.tests
219
200
def include_id_list(id_list, suite):
220
201
"""Returns the tests whose id are part of the list.
222
:param id_list: A TestIdList describing the tests that should be kept.
203
The order in the list is enforced in the returned suite. This provides a
204
way to strictly control the order of execution, making isolation issues
207
Note that this doesn't filter out duplicates in the list, instead, such
208
duplicates are provided twice.
210
:param id_list: A list of test ids that should be kept.
224
212
:param suite: The test suite to filter.
227
# No id list, no filtering
230
return filter_suite(lambda t: id_list.includes(t.id()), suite)
217
return suite.__class__()
219
filtered = suite.__class__()
220
for the_id in id_list:
223
return test.id() == the_id
224
just_the_id = filter_suite(is_the_id, suite)
225
# We don't want to wrap the filtered tests into two layers of
226
# suite.__class__ so we extract the single test.
227
if just_the_id.countTestCases():
228
# Keep only non-empty suites
229
filtered.addTest(list(just_the_id)[0])