Skip to content

Commit

Permalink
Merge pull request #115 from theskumar/skip-covered-support
Browse files Browse the repository at this point in the history
Add support for 'skip_covered' option in terminal report section
  • Loading branch information
ionelmc committed Jun 20, 2016
2 parents ec857bc + 69fed36 commit a1e8174
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -16,3 +16,4 @@ Authors
* Patrick Lannigan - https://github.com/unholysampler
* David Szotten - https://github.com/davidszotten
* Michael Elovskikh - https://github.com/wronglink
* Saurabh Kumar - https://github.com/theskumar
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -12,7 +12,8 @@ Changelog
Contributed by David Szotten in `PR#116 <https://github.com/pytest-dev/pytest-cov/pull/116>`_.
* Fixed bug occurred when bare ``--cov`` parameter was used with xdist.
Contributed by Michael Elovskikh in `PR#120 <https://github.com/pytest-dev/pytest-cov/pull/120>`_.

* Add support for ``skip_covered`` and added ``--cov-report=term-skip-covered`` command
line options. Contributed by Saurabh Kumar in `PR#115 <https://github.com/pytest-dev/pytest-cov/pull/115>`_.

2.2.1 (2016-01-30)
------------------
Expand Down
15 changes: 15 additions & 0 deletions README.rst
Expand Up @@ -223,6 +223,21 @@ The terminal report with line numbers::
--------------------------------------------------
TOTAL 353 20 94%

The terminal report with skip covered::

py.test --cov-report term:skip-covered --cov=myproj tests/

-------------------- coverage: platform linux2, python 2.6.4-final-0 ---------------------
Name Stmts Miss Cover
----------------------------------------
myproj/myproj 257 13 94%
myproj/feature4286 94 7 92%
----------------------------------------
TOTAL 353 20 94%

1 files skipped due to complete coverage.

You can use ``skip-covered`` with ``term-missing`` as well. e.g. ``--cov-report term-missing:skip-covered``

These three report options output to files without showing anything on the terminal::

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -13,6 +13,7 @@ norecursedirs =
.git
.tox
.env
venv
dist
build
south_migrations
Expand Down
13 changes: 10 additions & 3 deletions src/pytest_cov/engine.py
Expand Up @@ -83,9 +83,16 @@ def summary(self, stream):
self.sep(stream, ' ', '%s' % node_desc)

# Produce terminal report if wanted.
if 'term' in self.cov_report or 'term-missing' in self.cov_report:
show_missing = ('term-missing' in self.cov_report) or None
total = self.cov.report(show_missing=show_missing, ignore_errors=True, file=stream)
if any(x in self.cov_report for x in ['term', 'term-missing']):
options = {
'show_missing': ('term-missing' in self.cov_report) or None,
'ignore_errors': True,
'file': stream,
}
skip_covered = isinstance(self.cov_report, dict) and 'skip-covered' in self.cov_report.values()
if hasattr(coverage, 'version_info') and coverage.version_info[0] >= 4:
options.update({'skip_covered': skip_covered or None})
total = self.cov.report(**options)

# Produce annotated source code report if wanted.
if 'annotate' in self.cov_report:
Expand Down
6 changes: 6 additions & 0 deletions src/pytest_cov/plugin.py
Expand Up @@ -17,6 +17,7 @@ class CoverageError(Exception):
def validate_report(arg):
file_choices = ['annotate', 'html', 'xml']
term_choices = ['term', 'term-missing']
term_modifier_choices = ['skip-covered']
all_choices = term_choices + file_choices
values = arg.split(":", 1)
report_type = values[0]
Expand All @@ -27,6 +28,10 @@ def validate_report(arg):
if len(values) == 1:
return report_type, None

report_modifier = values[1]
if report_type in term_choices and report_modifier in term_modifier_choices:
return report_type, report_modifier

if report_type not in file_choices:
msg = 'output specifier not supported for: "{}" (choose from "{}")'.format(arg,
file_choices)
Expand Down Expand Up @@ -54,6 +59,7 @@ def pytest_addoption(parser):
metavar='type', type=validate_report,
help='type of report to generate: term, term-missing, '
'annotate, html, xml (multi-allowed). '
'term, term-missing maybe followed by ":skip-covered".'
'annotate, html and xml may be be followed by ":DEST" '
'where DEST specifies the output location.')
group.addoption('--cov-config', action='store', default='.coveragerc',
Expand Down
47 changes: 47 additions & 0 deletions tests/test_pytest_cov.py
Expand Up @@ -567,6 +567,7 @@ def test_central_subprocess_change_cwd_with_pythonpath(testdir, monkeypatch):
])
assert result.ret == 0


def test_central_subprocess_no_subscript(testdir):
script = testdir.makepyfile("""
import subprocess, sys
Expand Down Expand Up @@ -863,6 +864,52 @@ def test_coveragerc_dist(testdir):
['test_coveragerc_dist* %s' % EXCLUDED_RESULT])


SKIP_COVERED_COVERAGERC = '''
[report]
skip_covered = True
'''

SKIP_COVERED_TEST = '''
def func():
return "full coverage"
def test_basic():
assert func() == "full coverage"
'''

SKIP_COVERED_RESULT = '1 file skipped due to complete coverage.'


@pytest.mark.skipif('StrictVersion(coverage.__version__) < StrictVersion("4.0")')
@pytest.mark.parametrize('report_option', [
'term-missing:skip-covered',
'term:skip-covered'])
def test_skip_covered_cli(testdir, report_option):
testdir.makefile('', coveragerc=SKIP_COVERED_COVERAGERC)
script = testdir.makepyfile(SKIP_COVERED_TEST)
result = testdir.runpytest('-v',
'--cov=%s' % script.dirpath(),
'--cov-report=%s' % report_option,
script)
assert result.ret == 0
result.stdout.fnmatch_lines([SKIP_COVERED_RESULT])


@pytest.mark.skipif('StrictVersion(coverage.__version__) < StrictVersion("4.0")')
def test_skip_covered_coveragerc_config(testdir):
testdir.makefile('', coveragerc=SKIP_COVERED_COVERAGERC)
script = testdir.makepyfile(SKIP_COVERED_TEST)
result = testdir.runpytest('-v',
'--cov-config=coveragerc',
'--cov=%s' % script.dirpath(),
script)
assert result.ret == 0
result.stdout.fnmatch_lines([SKIP_COVERED_RESULT])


CLEAR_ENVIRON_TEST = '''
import os
Expand Down

0 comments on commit a1e8174

Please sign in to comment.