From f0b4afe7db15d8cd2dbd8a77c29dcaf8f7ddb5e4 Mon Sep 17 00:00:00 2001 From: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> Date: Wed, 15 Sep 2021 05:04:59 -0700 Subject: Raise exception when 1+ stand-alone tests fail (#25857) --- lib/spack/spack/install_test.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/spack/spack/install_test.py b/lib/spack/spack/install_test.py index dbc1ccc88b..8217d2f538 100644 --- a/lib/spack/spack/install_test.py +++ b/lib/spack/spack/install_test.py @@ -87,6 +87,8 @@ class TestSuite(object): 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 @@ class TestSuite(object): 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 @@ class TestSuite(object): 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 @@ class TestFailure(spack.error.SpackError): 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) -- cgit v1.2.3-60-g2f50