Skip to content

Commit

Permalink
Merge pull request #830 from Eric89GXL/no-print
Browse files Browse the repository at this point in the history
ENH: Allow not printing coverage report
  • Loading branch information
jszakmeister committed Jan 27, 2016
2 parents 344a215 + 049b295 commit 6e11bf9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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

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
19 changes: 12 additions & 7 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
coverPrint = True
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 @@ -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,
Expand All @@ -164,7 +171,6 @@ def configure(self, options, conf):
self.coverInstance.load()
self.coverInstance.start()


def beforeTest(self, *args, **kwargs):
"""
Begin recording coverage information.
Expand All @@ -183,7 +189,6 @@ def afterTest(self, *args, **kwargs):
self.coverInstance.stop()
self.coverInstance.save()


def report(self, stream):
"""
Output code coverage report.
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions unit_tests/test_cover_plugin.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 6e11bf9

Please # to comment.