From 822db03d54f5fe3b6064d582677d7b74474682f5 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Sun, 3 Aug 2014 10:12:23 -0700 Subject: ENH: Allow not printing coverage report --- CHANGELOG | 3 ++- README.txt | 4 ++++ nose/plugins/cover.py | 35 +++++++++++++---------------------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index fe2ed89..25d5090 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 @@ -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 67b8f29..2047e4e 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 0276f2d..0e8392a 100644 --- a/nose/plugins/cover.py +++ b/nose/plugins/cover.py @@ -29,6 +29,7 @@ class Coverage(Plugin): coverInstance = None coverErase = False coverMinPercentage = None + coverNoPrint = False score = 200 status = {} @@ -85,7 +86,8 @@ class Coverage(Plugin): 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 @@ class Coverage(Plugin): 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): """ @@ -140,10 +146,7 @@ class Coverage(Plugin): 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, @@ -153,19 +156,7 @@ class Coverage(Plugin): 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. """ @@ -193,10 +184,11 @@ class Coverage(Plugin): 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: @@ -237,7 +229,6 @@ class Coverage(Plugin): 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) -- cgit v1.2.1