changeset 144:76dea27af878

* Make the `<python:unittest>` command strip the base dir from file names in the report. Fixes #42. * Yield reports in the order they were generated. * The `testrunner` now splits the test name into `name` and `fixture` components (the former is commonly the name of the test function, while the latter is the name of the `TestCase` subclass. * Parse descriptions of doctests to extract the test fixture. * Add option to the `build.py` script to enable output of generated reports to the console.t
author cmlenz
date Sat, 20 Aug 2005 13:29:56 +0000
parents 236786389dfd
children 0221d7cdf59a
files bitten/build/pythontools.py bitten/recipe.py bitten/util/testrunner.py scripts/build.py
diffstat 4 files changed, 34 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/build/pythontools.py
+++ b/bitten/build/pythontools.py
@@ -138,12 +138,18 @@
         try:
             results = xmlio.Fragment()
             for child in xmlio.parse(fd).children():
-                filename = child.attr.get('file')
-                if filename:
-                    filename = os.path.realpath(filename)
-                    if filename.startswith(ctxt.basedir):
-                        child.attr['file'] = filename[len(ctxt.basedir) + 1:]
-                results.append(child)
+                test = xmlio.Element('test')
+                for name, value in child.attr.items():
+                    if name == 'file':
+                        value = os.path.realpath(value)
+                        if value.startswith(ctxt.basedir):
+                            value = value[len(ctxt.basedir) + 1:]
+                        else:
+                            continue
+                    test.attr[name] = value
+                for grandchild in child.children():
+                    test.append(grandchild)
+                results.append(test)
             ctxt.report(results)
         finally:
             fd.close()
--- a/bitten/recipe.py
+++ b/bitten/recipe.py
@@ -91,7 +91,7 @@
             ctxt.current_step = None
         errors = []
         while ctxt.output:
-            type, function, output = ctxt.output.pop()
+            type, function, output = ctxt.output.pop(0)
             yield type, function, output
             if type == Recipe.ERROR:
                 errors.append((function, output))
--- a/bitten/util/testrunner.py
+++ b/bitten/util/testrunner.py
@@ -87,9 +87,22 @@
                 status = 'failure'
                 tb = [f[1] for f in result.failures if f[0] is testcase][0]
 
-            test_elem = SubElement(root, 'test', file=filename, name=testcase,
-                                   status=status, duration=timetaken)
-            description = testcase.shortDescription()
+            name = str(testcase)
+            fixture = None
+            description = testcase.shortDescription() or ''
+            if description.startswith('doctest of '):
+                name = 'doctest'
+                fixture = description[11:]
+                description = None
+            else:
+                match = re.match('(\w+)\s+\(([\w.]+)\)', name)
+                if match:
+                    name = match.group(1)
+                    fixture = match.group(2)
+
+            test_elem = SubElement(root, 'test', file=filename, name=name,
+                                   fixture=fixture, status=status,
+                                   duration=timetaken)
             if description:
                 SubElement(test_elem, 'description')[description]
             if stdout:
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -32,6 +32,9 @@
 
     parser = OptionParser(usage='usage: %prog [options] [step1] [step2] ...',
                           version='%%prog %s' % VERSION)
+    parser.add_option('--print-reports', action='store_const',
+                      dest='print_reports', const=True,
+                      help='print generated reports')
     parser.add_option('-v', '--verbose', action='store_const', dest='loglevel',
                       const=logging.DEBUG, help='print as much as possible')
     parser.add_option('-q', '--quiet', action='store_const', dest='loglevel',
@@ -56,6 +59,8 @@
             for type, function, output in step.execute(recipe.ctxt):
                 if type == Recipe.ERROR:
                     log.error('Failure in step "%s": %s', step.id, output)
+                elif type == Recipe.REPORT and options.print_reports:
+                    output.write(sys.stdout, newlines=True)
             if step.id in steps_to_run:
                 steps_to_run[step.id] = True
 
Copyright (C) 2012-2017 Edgewall Software