From d50a18d9ebe38137690dfd0a6972616c0e07271c Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Wed, 25 Nov 2015 17:10:45 -0800 Subject: XML output for unit tests is now enabled with an option (disabled by default) --- lib/spack/spack/cmd/test.py | 21 ++++++++++++++------- lib/spack/spack/test/__init__.py | 12 +++++++----- lib/spack/spack/test/tally_plugin.py | 1 + 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/spack/spack/cmd/test.py b/lib/spack/spack/cmd/test.py index 001ebfaef0..f93d126851 100644 --- a/lib/spack/spack/cmd/test.py +++ b/lib/spack/spack/cmd/test.py @@ -39,9 +39,12 @@ 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") + '--createXmlOutput', action='store_true', dest='createXmlOutput', + help="Create JUnit XML from test results") + subparser.add_argument( + '--xmlOutputDir', dest='xmlOutputDir', + help="Nose creates XML files in this directory") subparser.add_argument( '-v', '--verbose', action='store_true', dest='verbose', help="verbose output") @@ -53,10 +56,14 @@ def test(parser, args): colify(spack.test.list_tests(), indent=2) else: - if not args.outputDir: - outputDir = join_path(os.getcwd(), "test-output") + if not args.createXmlOutput: + outputDir = None else: - outputDir = args.outputDir - if not os.path.exists(outputDir): - mkdirp(outputDir) + if not args.xmlOutputDir: + outputDir = join_path(os.getcwd(), "test-output") + else: + outputDir = os.path.abspath(args.xmlOutputDir) + + 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 158e8bdfcb..cb75f15ca1 100644 --- a/lib/spack/spack/test/__init__.py +++ b/lib/spack/spack/test/__init__.py @@ -92,11 +92,13 @@ def run(names, outputDir, verbose=False): tty.msg("Running test: %s" % test) - 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)] + runOpts = ["--with-%s" % spack.test.tally_plugin.Tally.name] + + if outputDir: + xmlOutputFname = "unittests-{0}.xml".format(test) + xmlOutputPath = join_path(outputDir, xmlOutputFname) + runOpts += ["--with-xunit", + "--xunit-file={0}".format(xmlOutputPath)] argv = [""] + runOpts + [module] result = nose.run(argv=argv, addplugins=[tally]) diff --git a/lib/spack/spack/test/tally_plugin.py b/lib/spack/spack/test/tally_plugin.py index e314fae6ce..c167d58529 100644 --- a/lib/spack/spack/test/tally_plugin.py +++ b/lib/spack/spack/test/tally_plugin.py @@ -35,6 +35,7 @@ class Tally(Plugin): self.failCount = 0 self.errorCount = 0 + # TODO: this doesn't account for the possibility of skipped tests @property def numberOfTests(self): return self.errorCount + self.failCount + self.successCount -- cgit v1.2.3-70-g09d2