Make sure from-filenames intersect with names-file

When both names-file an from-names are defined we want to make sure the
tests that from-filenames returns intersect with the test in the names
file.
This commit is contained in:
Daniel A. Wozniak 2018-10-14 22:20:57 -07:00 committed by Erik Johnson
parent ed864ceb28
commit 25097f9933
No known key found for this signature in database
GPG key ID: 5E5583C437808F3F

View file

@ -193,7 +193,7 @@ class SaltTestingParser(optparse.OptionParser):
'--name',
dest='name',
action='append',
default=None,
default=[],
help=('Specific test name to run. A named test is the module path '
'relative to the tests directory')
)
@ -449,27 +449,23 @@ class SaltTestingParser(optparse.OptionParser):
def parse_args(self, args=None, values=None):
self.options, self.args = optparse.OptionParser.parse_args(self, args, values)
file_names = []
if self.options.names_file:
with open(self.options.names_file, 'rb') as fp_: # pylint: disable=resource-leakage
lines = []
for line in fp_.readlines():
if six.PY2:
lines.append(line.strip())
file_names.append(line.strip())
else:
lines.append(
file_names.append(
line.decode(__salt_system_encoding__).strip())
if self.options.name:
self.options.name.extend(lines)
else:
self.options.name = lines
if self.args:
if not self.options.name:
self.options.name = []
for fpath in self.args:
if os.path.isfile(fpath) and \
fpath.endswith('.py') and \
os.path.basename(fpath).startswith('test_'):
self.options.name.append(fpath)
if fpath in file_names:
self.options.name.append(fpath)
continue
self.exit(status=1, msg='\'{}\' is not a valid test module'.format(fpath))
@ -483,11 +479,12 @@ class SaltTestingParser(optparse.OptionParser):
'filename_map.yml'
)
mapped_mods = self._map_files(self.options.from_filenames)
if mapped_mods:
if self.options.name is None:
self.options.name = []
self.options.name.extend(mapped_mods)
self.options.name.extend(self._map_files(self.options.from_filenames))
if self.options.name and file_names:
self.options.name = list(set(self.options.name).intersection(file_names))
elif file_names:
self.options.name = file_names
print_header(u'', inline=True, width=self.options.output_columns)
self.pre_execution_cleanup()