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`.
This commit is contained in:
parent
b2ece3abba
commit
61baa40160
@ -7,6 +7,7 @@
|
|||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import inspect
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@ -194,6 +195,9 @@ def test_run(args):
|
|||||||
|
|
||||||
|
|
||||||
def has_test_method(pkg):
|
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
|
pkg_base = spack.package.PackageBase
|
||||||
return (
|
return (
|
||||||
(issubclass(pkg, pkg_base) and pkg.test != pkg_base.test) or
|
(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
|
hashes = env.all_hashes() if env else None
|
||||||
|
|
||||||
specs = spack.store.db.query(hashes=hashes)
|
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)
|
spack.cmd.display_specs(specs, long=True)
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
import spack.config
|
import spack.config
|
||||||
import spack.package
|
import spack.package
|
||||||
import spack.cmd.install
|
import spack.cmd.install
|
||||||
|
|
||||||
|
from spack.cmd.test import has_test_method
|
||||||
from spack.main import SpackCommand
|
from spack.main import SpackCommand
|
||||||
|
|
||||||
install = SpackCommand('install')
|
install = SpackCommand('install')
|
||||||
@ -183,7 +185,7 @@ def test_test_help_cdash(mock_test_stage):
|
|||||||
assert 'CDash URL' in out
|
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"""
|
"""make sure `spack test list --all` returns all packages with tests"""
|
||||||
pkgs = spack_test("list", "--all").strip().split()
|
pkgs = spack_test("list", "--all").strip().split()
|
||||||
assert set(pkgs) == set([
|
assert set(pkgs) == set([
|
||||||
@ -193,3 +195,20 @@ def test_list_all(mock_packages):
|
|||||||
"test-error",
|
"test-error",
|
||||||
"test-fail",
|
"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
|
||||||
|
Loading…
Reference in New Issue
Block a user