Skip to content
Snippets Groups Projects
Commit 90f2154a authored by Todd Gamblin's avatar Todd Gamblin
Browse files

Better test output -- include totals.

parent 87fedc7e
Branches
Tags
No related merge requests found
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
def setup_parser(subparser): def setup_parser(subparser):
subparser.add_argument( subparser.add_argument(
'names', nargs='*', help="Names of packages to install") 'names', nargs='*', help="Names of tests to run.")
subparser.add_argument( subparser.add_argument(
'-l', '--list', action='store_true', dest='list', help="Show available tests") '-l', '--list', action='store_true', dest='list', help="Show available tests")
subparser.add_argument( subparser.add_argument(
...@@ -17,24 +17,10 @@ def setup_parser(subparser): ...@@ -17,24 +17,10 @@ def setup_parser(subparser):
help="verbose output") help="verbose output")
def find_test_modules():
"""Include all the modules under test, unless they set skip_test=True"""
for name in list_modules(spack.test_path):
module = __import__('spack.test.' + name, fromlist='skip_test')
if not getattr(module, 'skip_test', False):
yield name
def test(parser, args): def test(parser, args):
if args.list: if args.list:
print "Available tests:" print "Available tests:"
colify(find_test_modules()) colify(spack.test.list_tests(), indent=2)
elif not args.names:
for name in find_test_modules():
print "Running Tests: %s" % name
spack.test.run(name, verbose=args.verbose)
else: else:
for name in args.names: spack.test.run(args.names, args.verbose)
spack.test.run(name, verbose=args.verbose)
import sys import sys
import unittest import unittest
import spack import spack
from spack.colify import colify
import spack.tty as tty
test_names = ['versions',
'url_parse',
'stage',
'spec_syntax',
'spec_dag',
'concretize']
def list_tests():
return test_names
def run(names, verbose=False):
verbosity = 1 if not verbose else 2
if not names:
names = test_names
else:
for test in names:
if test not in test_names:
tty.error("%s is not a valid spack test name." % test,
"Valid names are:")
colify(test_names, indent=4)
sys.exit(1)
runner = unittest.TextTestRunner(verbosity=verbosity)
testsRun = errors = failures = skipped = 0
for test in names:
module = 'spack.test.' + test
suite = unittest.defaultTestLoader.loadTestsFromName(module)
def run(test_name, verbose=False): tty.msg("Running test: %s" % test)
__import__(__package__ + "." + test_name) result = runner.run(suite)
testsRun += result.testsRun
errors += len(result.errors)
failures += len(result.failures)
skipped += len(result.skipped)
# This just runs unittest.main on the module with the provided name succeeded = not errors and not failures
test_module = getattr(spack.test, test_name) tty.msg("Tests Complete.",
"%5d tests run" % testsRun,
"%5d skipped" % skipped,
"%5d failures" % failures,
"%5d errors" % errors)
verbosity=1 if not errors and not failures:
if verbose: verbosity = 2 tty.info("OK", format='g')
unittest.main(module=test_module, argv=sys.argv[:1], verbosity=verbosity, exit=False) else:
tty.info("FAIL", format='r')
sys.exit(1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment