Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage #1328

Merged
merged 5 commits into from
Jan 27, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 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,9 +287,19 @@ def __init__(self, runner='iptest', params=None):
# Assemble call
self.call_args = self.runner+self.params

# Find the section we're testing (IPython.foo)
for sect in self.params:
if sect.startswith('IPython'): break
else:
raise ValueError("Section not found", self.params)

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-xml-coverage' in self.call_args:
self.coverage_xml = path.abspath(sect+".coverage.xml")
self.call_args.remove('--with-xml-coverage')
self.call_args = ["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 @@ -319,11 +331,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.call(["coverage", "xml", "-o", self.coverage_xml])
return retcode

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