diff --git a/CHANGELOG b/CHANGELOG index fe2ed898..902d606c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,8 @@ - Fix loading packages from capitalised package on Windows Patch by Thomas Kluyver +- Add option to suppress printing of coverage report + Patch by Eric Larson. 1.3.6 @@ -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 - diff --git a/README.txt b/README.txt index 67b8f29f..2047e4e3 100644 --- a/README.txt +++ b/README.txt @@ -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 diff --git a/nose/plugins/cover.py b/nose/plugins/cover.py index 0276f2dc..4bae004e 100644 --- a/nose/plugins/cover.py +++ b/nose/plugins/cover.py @@ -29,6 +29,7 @@ class Coverage(Plugin): coverInstance = None coverErase = False coverMinPercentage = None + coverPrint = True score = 200 status = {} @@ -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") @@ -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): """ @@ -144,6 +150,7 @@ def configure(self, options, conf): self.coverConfigFile = True if options.cover_config_file: self.coverConfigFile = options.cover_config_file + self.coverPrint = not options.cover_no_print if self.enabled: self.status['active'] = True self.coverInstance = coverage.coverage(auto_data=False, @@ -164,7 +171,6 @@ def configure(self, options, conf): self.coverInstance.load() self.coverInstance.start() - def beforeTest(self, *args, **kwargs): """ Begin recording coverage information. @@ -183,7 +189,6 @@ def afterTest(self, *args, **kwargs): self.coverInstance.stop() self.coverInstance.save() - def report(self, stream): """ Output code coverage report. @@ -193,10 +198,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 self.coverPrint: + self.coverInstance.report(modules, file=stream) import coverage if self.coverHtmlDir: @@ -237,7 +243,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) diff --git a/unit_tests/test_cover_plugin.py b/unit_tests/test_cover_plugin.py index b95c590f..59994130 100644 --- a/unit_tests/test_cover_plugin.py +++ b/unit_tests/test_cover_plugin.py @@ -1,10 +1,8 @@ import os -import sys from optparse import OptionParser from nose.config import Config from nose.plugins.cover import Coverage from nose.tools import eq_ -import unittest class TestCoveragePlugin(object): @@ -14,6 +12,11 @@ def test_cover_options_packages(self): ['pkg1', 'pkg2', 'pkg3'], [], 'pkg1,pkg2,pkg3', 'NOSE_COVER_PACKAGE') + def test_cover_options_noprint(self): + _test_options_helper('--cover-no-print', 'coverPrint', + False, True, + env_key='NOSE_COVER_NO_PRINT') + def test_cover_options_erase(self): _test_options_helper('--cover-erase', 'coverErase', True, False, @@ -63,6 +66,7 @@ def get_config_files(cov_info): finally: os.unlink('not_default_config_file') + def _test_options_helper(arg_option, cover_option, expected_set, expected_not_set, arg_value=None, env_key=None):