Skip to content

Commit

Permalink
Produce coverage xml reports from subprocess test runners.
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Jan 25, 2012
1 parent bf55239 commit bad4947
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions IPython/testing/iptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ class IPTester(object):
call_args = None
#: list, process ids of subprocesses we start (for cleanup)
pids = None
#: str, coverage xml output file
coverage_xml = None

def __init__(self, runner='iptest', params=None):
"""Create new test runner."""
Expand All @@ -285,10 +287,14 @@ def __init__(self, runner='iptest', params=None):
# Assemble call
self.call_args = self.runner+self.params

print self.call_args
sect = [p for p in self.params if p.startswith('IPython')][0]
if '--with-xunit' in self.call_args:
sect = [p for p in self.params if p.startswith('IPython')][0]
self.call_args.append('--xunit-file=%s' % path.abspath(sect+'.xunit.xml'))

if '--with-coverage' in self.call_args:
self.coverage_xml = path.abspath(sect+".coverage.xml")
self.call_args.remove('--with-coverage')
self.call_args = ["python-coverage", "run", "--source="+sect] + self.call_args[1:]

# Store pids of anything we start to clean up on deletion, if possible
# (on posix only, since win32 has no os.kill)
Expand Down Expand Up @@ -320,11 +326,15 @@ def _run_cmd(self):
def run(self):
"""Run the stored commands"""
try:
return self._run_cmd()
retcode = self._run_cmd()
except:
import traceback
traceback.print_exc()
return 1 # signal failure

if self.coverage_xml:
subprocess.check_call(["python-coverage", "xml", "-o", self.coverage_xml])
return retcode

def __del__(self):
"""Cleanup on exit by killing any leftover processes."""
Expand Down

0 comments on commit bad4947

Please sign in to comment.