From 18dea24df8710bb65fd61278fb6bdf45d28d2aa6 Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Tue, 24 Nov 2015 19:08:37 -0800 Subject: Use the xunit nose plugin to generate JUnit XML test results from Spack's unit tests. --- lib/spack/spack/cmd/test.py | 13 ++++++++++++- lib/spack/spack/test/__init__.py | 12 +++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/cmd/test.py b/lib/spack/spack/cmd/test.py index b1418ac2f1..001ebfaef0 100644 --- a/lib/spack/spack/cmd/test.py +++ b/lib/spack/spack/cmd/test.py @@ -22,8 +22,10 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ############################################################################## +import os from pprint import pprint +from llnl.util.filesystem import join_path, mkdirp from llnl.util.tty.colify import colify from llnl.util.lang import list_modules @@ -37,6 +39,9 @@ def setup_parser(subparser): 'names', nargs='*', help="Names of tests to run.") subparser.add_argument( '-l', '--list', action='store_true', dest='list', help="Show available tests") + # TODO: make XML output optional + subparser.add_argument( + '-d', '--outputDir', dest='outputDir', help="Nose creates XML files in this directory") subparser.add_argument( '-v', '--verbose', action='store_true', dest='verbose', help="verbose output") @@ -48,4 +53,10 @@ def test(parser, args): colify(spack.test.list_tests(), indent=2) else: - spack.test.run(args.names, args.verbose) + if not args.outputDir: + outputDir = join_path(os.getcwd(), "test-output") + else: + outputDir = args.outputDir + if not os.path.exists(outputDir): + mkdirp(outputDir) + spack.test.run(args.names, outputDir, args.verbose) diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py index 327a4886b9..158e8bdfcb 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -27,6 +27,7 @@ import unittest import nose from spack.test.tally_plugin import Tally +from llnl.util.filesystem import join_path import llnl.util.tty as tty from llnl.util.tty.colify import colify @@ -69,7 +70,7 @@ def list_tests(): return test_names -def run(names, verbose=False): +def run(names, outputDir, verbose=False): """Run tests with the supplied names. Names should be a list. If it's empty, run ALL of Spack's tests.""" verbosity = 1 if not verbose else 2 @@ -91,8 +92,13 @@ def run(names, verbose=False): tty.msg("Running test: %s" % test) - activateTally = "--with-%s" % spack.test.tally_plugin.Tally.name - result = nose.run(argv=["", activateTally, module], addplugins=[tally]) + xmlOutputFname = "unittests-{0}.xml".format(test) + xmlOutputPath = join_path(outputDir, xmlOutputFname) + runOpts = ["--with-%s" % spack.test.tally_plugin.Tally.name, + "--with-xunit", + "--xunit-file={0}".format(xmlOutputPath)] + argv = [""] + runOpts + [module] + result = nose.run(argv=argv, addplugins=[tally]) succeeded = not tally.failCount and not tally.errorCount tty.msg("Tests Complete.", -- cgit v1.2.3-60-g2f50