diff options
author | Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> | 2021-03-12 09:56:17 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-12 09:56:17 -0800 |
commit | 61baa40160c64097943e8e0852de1e516970352a (patch) | |
tree | c00b4a2a164a0cd05b8a3c3445229d6dac8e4f65 /lib | |
parent | b2ece3abba4371ca3362a3b9a2e67c0484c45a27 (diff) | |
download | spack-61baa40160c64097943e8e0852de1e516970352a.tar.gz spack-61baa40160c64097943e8e0852de1e516970352a.tar.bz2 spack-61baa40160c64097943e8e0852de1e516970352a.tar.xz spack-61baa40160c64097943e8e0852de1e516970352a.zip |
bugfix: ensure spack test list still works (#22203)
Was getting the following error:
```
$ spack test list
==> Error: issubclass() arg 1 must be a class
```
This PR adds a check in `has_test_method` (in case it is re-used elsewhere such as #22097) and ensures a class is passed to the method from `spack test list`.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/cmd/test.py | 6 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/test.py | 21 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lib/spack/spack/cmd/test.py b/lib/spack/spack/cmd/test.py index 87dce7a19f..343c019bce 100644 --- a/lib/spack/spack/cmd/test.py +++ b/lib/spack/spack/cmd/test.py @@ -7,6 +7,7 @@ from __future__ import print_function import os import argparse import textwrap +import inspect import fnmatch import re import shutil @@ -194,6 +195,9 @@ environment variables: def has_test_method(pkg): + if not inspect.isclass(pkg): + tty.die('{0}: is not a class, it is {1}'.format(pkg, type(pkg))) + pkg_base = spack.package.PackageBase return ( (issubclass(pkg, pkg_base) and pkg.test != pkg_base.test) or @@ -220,7 +224,7 @@ def test_list(args): hashes = env.all_hashes() if env else None specs = spack.store.db.query(hashes=hashes) - specs = list(filter(lambda s: has_test_method(s.package), specs)) + specs = list(filter(lambda s: has_test_method(s.package_class), specs)) spack.cmd.display_specs(specs, long=True) diff --git a/lib/spack/spack/test/cmd/test.py b/lib/spack/spack/test/cmd/test.py index da360f14dd..c0471fdfca 100644 --- a/lib/spack/spack/test/cmd/test.py +++ b/lib/spack/spack/test/cmd/test.py @@ -11,6 +11,8 @@ import pytest import spack.config import spack.package import spack.cmd.install + +from spack.cmd.test import has_test_method from spack.main import SpackCommand install = SpackCommand('install') @@ -183,7 +185,7 @@ def test_test_help_cdash(mock_test_stage): assert 'CDash URL' in out -def test_list_all(mock_packages): +def test_test_list_all(mock_packages): """make sure `spack test list --all` returns all packages with tests""" pkgs = spack_test("list", "--all").strip().split() assert set(pkgs) == set([ @@ -193,3 +195,20 @@ def test_list_all(mock_packages): "test-error", "test-fail", ]) + + +def test_test_list( + mock_packages, mock_archive, mock_fetch, install_mockery_mutable_config +): + pkg_with_tests = 'printing-package' + install(pkg_with_tests) + output = spack_test("list") + assert pkg_with_tests in output + + +def test_has_test_method_fails(capsys): + with pytest.raises(SystemExit): + has_test_method('printing-package') + + captured = capsys.readouterr()[1] + assert 'is not a class' in captured |