From b6169c213de742dc036d6eec0079bd22ee377071 Mon Sep 17 00:00:00 2001 From: Cory Bloor Date: Fri, 1 Oct 2021 17:40:24 -0600 Subject: [PATCH] Fix error message when test throws AttributeError (#25895) Narrow the scope of the try/except block, to avoid a misleading error message if fn() throws an AttributeError. --- lib/spack/spack/package.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py index b3dbb5a2b5..e881fee522 100644 --- a/lib/spack/spack/package.py +++ b/lib/spack/spack/package.py @@ -2551,11 +2551,12 @@ def _run_default_build_time_test_callbacks(self): for name in self.build_time_test_callbacks: try: fn = getattr(self, name) - tty.msg('RUN-TESTS: build-time tests [{0}]'.format(name)) - fn() except AttributeError: msg = 'RUN-TESTS: method not implemented [{0}]' tty.warn(msg.format(name)) + else: + tty.msg('RUN-TESTS: build-time tests [{0}]'.format(name)) + fn() @on_package_attributes(run_tests=True) def _run_default_install_time_test_callbacks(self): @@ -2570,11 +2571,12 @@ def _run_default_install_time_test_callbacks(self): for name in self.install_time_test_callbacks: try: fn = getattr(self, name) - tty.msg('RUN-TESTS: install-time tests [{0}]'.format(name)) - fn() except AttributeError: msg = 'RUN-TESTS: method not implemented [{0}]' tty.warn(msg.format(name)) + else: + tty.msg('RUN-TESTS: install-time tests [{0}]'.format(name)) + fn() def test_process(pkg, kwargs):