Fix error message when test throws AttributeError (#25895)
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.
LLNL/spack,LLNL/spack,LLNL/spack,LLNL/spack,LLNL/spack