Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option --cov-summary to show coverage summary in terminal #140

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def pytest_addoption(parser):
group.addoption('--cov-append', action='store_true', default=False,
help='do not delete coverage but append to current, '
'default: False')
group.addoption('--cov-summary', action='store_true', default=False,
help='show coverage summary in terminal, '
'default: False')


@pytest.mark.tryfirst
Expand Down Expand Up @@ -258,6 +261,11 @@ def pytest_terminal_summary(self, terminalreporter):

terminalreporter.write('\n' + self.cov_report.getvalue() + '\n')

if self.options.cov_summary:
if self.options.cov_fail_under is not None:
terminalreporter.write('Required coverage: %d%%\n' % self.options.cov_fail_under)
terminalreporter.write('Total coverage: %.2f%%\n' % self.cov_total)

if self._failed_cov_total():
markup = {'red': True, 'bold': True}
msg = (
Expand Down
21 changes: 21 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,3 +1126,24 @@ def test_do_not_append_coverage(testdir, opts):
'test_1* 0%',
'test_2* %s*' % SCRIPT2_RESULT,
])


def test_cov_summary(testdir):
script = testdir.makepyfile(SCRIPT)

result = testdir.runpytest('-v',
'--cov=%s' % script.dirpath(),
'--cov-summary',
script)
result.stdout.fnmatch_lines([
'Total coverage: *'
])
result = testdir.runpytest('-v',
'--cov=%s' % script.dirpath(),
'--cov-fail-under=50',
'--cov-summary',
script)
result.stdout.fnmatch_lines([
'Required coverage: *',
'Total coverage: *'
])