Add support for whitelist to tests2skip

tests2skip currently implements a test blacklist for testr.
Extending this to include a whitelist.
Whitelist is applied first. The blacklist is  executed against
the set of tests returned by the whitelist.
This way it is possible to use test selection like those from
tox.ini in tempest, and exclude some tests from them.
If whitelist is empty, all available tests are fed to blacklist.
If blacklist is empty, all tests from whitelist are returned.

The syntax for white-list and black-list is as follows:
- lines starting with # or empty are ignored
- lines starting with "+" are whitelisted
- lines starting with "-" are blacklisted
- lines not matching any of the above conditions are blacklisted

The match for each line gets added a "^" in the beginning,
so the regular expression should account for that.

For example, the following scenario:

  run all the smoke tests and scenario tests,
  but exclude the api.volume tests.

is implemented as:

  +.*smoke
  +tempest\.scenario
  -tempest\.api\.volume.*

Change-Id: Iccea6a9ebc0a298ccb16ee33ac7461db72f3a414
This commit is contained in:
Andrea Frittoli 2014-04-09 14:38:01 +01:00
parent 1ca1abfd1c
commit 2675524482
1 changed files with 44 additions and 3 deletions

View File

@ -20,11 +20,52 @@
import sys
re = []
"""
Whitelist is applied first. The blacklist is executed against the set of
tests returned by the whitelist.
If whitelist is empty, all available tests are fed to blacklist.
If blacklist is empty, all tests from whitelist are returned.
The syntax for white-list and black-list is as follows:
- lines starting with # or empty are ignored
- lines starting with "+" are whitelisted
- lines starting with "-" are blacklisted
- lines not matching any of the above conditions are blacklisted
The match for each line gets added a "^" in the beginning,
so the regular expression should account for that.
For example, the following scenario:
run all the smoke tests and scenario tests,
but exclude the api.volume tests.
is implemented as:
+.*smoke
+tempest\.scenario
-tempest\.api\.volume.*
"""
whitelist = []
blacklist = []
with open(sys.argv[1]) as fp:
for line in fp:
line = line.strip()
if not line or line[0] == '#':
continue
re.append(line)
print("^(?!(%s))" % "|".join(re))
if line.startswith("+"):
whitelist.append(line[1:])
elif line.startswith("-"):
blacklist.append(line[1:])
else:
blacklist.append(line)
regex = '^(?=({whitelist}))'
params = dict(whitelist="|".join(whitelist))
if blacklist:
regex += '(?!({blacklist}))'
params['blacklist'] = "|".join(blacklist)
print(regex.format(**params))