1. Noufal Ibrahim
  2. pytest-coverage

Commits

prologic  committed 55a0426

Added 'coverage' funcarg to our plugin object DoCoverage.

Comments (0)

Files changed (1)

File pytest_coverage.py Modified

View file
  • Ignore whitespace
  • Hide word diff
         config.pluginmanager.register(DoCoverage(config), "coverage")
 
 class DoCoverage:
+
     def __init__(self, config):
         self.config = config 
-        import coverage
-        self.cov = coverage.coverage()
-        self.cov.use_cache(0) # Do not cache any of the coverage.py stuff
-        self.cov.start()
+
+        self._coverage = coverage()
+        self._coverage.use_cache(False)
+        self._coverage.start()
+
+    def pytest_funcarg__coverage(self, request):
+        return self._coverage
 
     def pytest_terminal_summary(self, terminalreporter):
+        self._coverage.stop()
+        self._coverage.save()
+
         config = terminalreporter.config
         tw = terminalreporter._tw
         tw.sep('-', 'coverage')
         tw.line('Processing Coverage...')
-        self.cov.stop()
-        self.cov.save()
         
         # Get the configurations
         config = terminalreporter.config
         #    report_args['omit_prefixes'] = omit_prefixes
         
         if report_type == 'report':
-            self.cov.report(show_missing=show_missing, file=tw, **report_args)
+            self._coverage.report(show_missing=show_missing, file=tw,
+                    **report_args)
         elif report_type == 'annotate':
-            self.cov.annotate(directory=directory, **report_type)
+            self._coverage.annotate(directory=directory, **report_type)
         elif report_type == 'html':
-            self.cov.html_report(directory=directory, **report_args)
+            self._coverage.html_report(directory=directory, **report_args)