[checker] run the pycoverage xml generation in a subprocess draft
authorDavid Douard <david.douard@logilab.fr>
Fri, 22 Jan 2016 17:07:51 +0100
changeset 1861 651a4a4dc1dd
parent 1860 61e4fff20c97
child 1862 6063a2a6ee8c
[checker] run the pycoverage xml generation in a subprocess so that it uses the same version of pycoverage as the one used to produce the coverage data (ie. when running the tests in a venv).
_narval/checkers/apycot/python.py
--- a/_narval/checkers/apycot/python.py	Fri Jan 22 17:08:39 2016 +0100
+++ b/_narval/checkers/apycot/python.py	Fri Jan 22 17:07:51 2016 +0100
@@ -100,7 +100,6 @@
         with open(pkginfopath) as f:
             exec(f.read(), pkginfo)
         if 'packages' in pkginfo:
-            import imp
             for pkg in pkginfo['packages']:
                 # do this in a subprocess since we execute our tests
                 # in a virtualenv...
@@ -258,8 +257,6 @@
     def enable_coverage(self):
         if self.options.get('pycoverage'):
             self.coverage_data = join(self.cwd, '.coverage')
-            # XXX we need the environment variable to be considered by
-            # "python-coverage run"
             os.environ['COVERAGE_FILE'] = self.coverage_data
             return True
         return False
@@ -672,12 +669,10 @@
         return writer
 
     def _get_cover_info(self, test):
-        covertool = coverage.coverage()
-        covertool.use_cache(self.options.get('coverage_data'))
-        covertool.load()
         try:
             report_file = join(test.project_path(), "coverage.xml")
-            covertool.xml_report(outfile=report_file, ignore_errors=True)
+            os.environ['COVERAGE_FILE'] = self.options.get('coverage_data')
+            check_output(['python', '-m', 'coverage', 'xml', '-o', report_file])
             report = etree.parse(report_file).getroot()
             pc_cover = float(report.attrib.get('line-rate'))
             br_rate  = float(report.attrib.get('branch-rate'))