Raise exception when 1+ stand-alone tests fail (#25857)

This commit is contained in:
Tamara Dahlgren 2021-09-15 05:04:59 -07:00 committed by GitHub
parent 75497537a4
commit f0b4afe7db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,6 +87,8 @@ def __init__(self, specs, alias=None):
self.alias = alias
self._hash = None
self.fails = 0
@property
def name(self):
return self.alias if self.alias else self.content_hash
@ -135,6 +137,7 @@ def __call__(self, *args, **kwargs):
shutil.rmtree(test_dir)
self.write_test_result(spec, 'PASSED')
except BaseException as exc:
self.fails += 1
if isinstance(exc, SyntaxError):
# Create the test log file and report the error.
self.ensure_stage()
@ -150,6 +153,9 @@ def __call__(self, *args, **kwargs):
self.current_test_spec = None
self.current_base_spec = None
if self.fails:
raise TestSuiteFailure(self.fails)
def ensure_stage(self):
if not os.path.exists(self.stage):
fs.mkdirp(self.stage)
@ -269,3 +275,11 @@ def __init__(self, failures):
msg += '\n%s\n' % message
super(TestFailure, self).__init__(msg)
class TestSuiteFailure(spack.error.SpackError):
"""Raised when one or more tests in a suite have failed."""
def __init__(self, num_failures):
msg = "%d test(s) in the suite failed.\n" % num_failures
super(TestSuiteFailure, self).__init__(msg)