Skip to content

Commit

Permalink
ENH: Allow not printing coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Jan 27, 2016
1 parent 344a215 commit 822db03
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

1.3.3

- Add option to suppress printing of coverage report
Patch by Eric Larson.
- Fixed a minor issue with the reported version number.

1.3.2
Expand Down Expand Up @@ -883,4 +885,3 @@
- Increased compatibility with python 2.3 (and maybe earlier)
- Increased compatibility with tests written for py.test: now calls
module.setup_module(module) if module.setup_module() fails

4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ Options

Location of coverage config file [NOSE_COVER_CONFIG_FILE]

--cover-no-print

Suppress printing of coverage information

--pdb

Drop into debugger on failures or errors
Expand Down
35 changes: 13 additions & 22 deletions nose/plugins/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Coverage(Plugin):
coverInstance = None
coverErase = False
coverMinPercentage = None
coverNoPrint = False
score = 200
status = {}

Expand Down Expand Up @@ -85,7 +86,8 @@ def options(self, parser, env):
dest="cover_xml",
help="Produce XML coverage information")
parser.add_option("--cover-xml-file", action="store",
default=env.get('NOSE_COVER_XML_FILE', 'coverage.xml'),
default=env.get('NOSE_COVER_XML_FILE',
'coverage.xml'),
dest="cover_xml_file",
metavar="FILE",
help="Produce XML coverage information in file")
Expand All @@ -94,6 +96,10 @@ def options(self, parser, env):
dest="cover_config_file",
help="Location of coverage config file "
"[NOSE_COVER_CONFIG_FILE]")
parser.add_option("--cover-no-print", action="store_true",
default=env.get('NOSE_COVER_NO_PRINT'),
dest="cover_no_print",
help="Suppress printing of coverage information")

def configure(self, options, conf):
"""
Expand Down Expand Up @@ -140,10 +146,7 @@ def configure(self, options, conf):
if options.cover_xml:
self.coverXmlFile = options.cover_xml_file
log.debug('Will put XML coverage report in %s', self.coverXmlFile)
# Coverage uses True to mean default
self.coverConfigFile = True
if options.cover_config_file:
self.coverConfigFile = options.cover_config_file
self.coverNoPrint = options.cover_no_print
if self.enabled:
self.status['active'] = True
self.coverInstance = coverage.coverage(auto_data=False,
Expand All @@ -153,19 +156,7 @@ def configure(self, options, conf):
self.coverInstance.is_worker = conf.worker
self.coverInstance.exclude('#pragma[: ]+[nN][oO] [cC][oO][vV][eE][rR]')

log.debug("Coverage begin")
self.skipModules = sys.modules.keys()[:]
if self.coverErase:
log.debug("Clearing previously collected coverage statistics")
self.coverInstance.combine()
self.coverInstance.erase()

if not self.coverInstance.is_worker:
self.coverInstance.load()
self.coverInstance.start()


def beforeTest(self, *args, **kwargs):
def begin(self):
"""
Begin recording coverage information.
"""
Expand Down Expand Up @@ -193,10 +184,11 @@ def report(self, stream):
self.coverInstance.combine()
self.coverInstance.save()
modules = [module
for name, module in sys.modules.items()
if self.wantModuleCoverage(name, module)]
for name, module in sys.modules.items()
if self.wantModuleCoverage(name, module)]
log.debug("Coverage report will cover modules: %s", modules)
self.coverInstance.report(modules, file=stream)
if not self.coverNoPrint:
self.coverInstance.report(modules, file=stream)

import coverage
if self.coverHtmlDir:
Expand Down Expand Up @@ -237,7 +229,6 @@ def report(self, stream):
log.error("No total percentage was found in coverage output, "
"something went wrong.")


def wantModuleCoverage(self, name, module):
if not hasattr(module, '__file__'):
log.debug("no coverage of %s: no __file__", name)
Expand Down

0 comments on commit 822db03

Please # to comment.