Skip to content

Added support of requiring minimum coverage percentage using cov-min #31

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

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 12 additions & 1 deletion pytest_cov.py
Original file line number Diff line number Diff line change
@@ -8,6 +8,10 @@
import cov_core_init


class CoverageError(Exception):
'''Indicates that our coverage is too low'''


def pytest_addoption(parser):
"""Add options to control coverage."""

@@ -30,6 +34,9 @@ def pytest_addoption(parser):
dest='no_cov_on_fail',
help='do not report coverage if test run fails, '
'default: False')
group.addoption('--cov-min', action='store', metavar='MIN', type='int',
help='Fail if the total coverage is less than MIN.')



@pytest.mark.tryfirst
@@ -135,7 +142,11 @@ def pytest_terminal_summary(self, terminalreporter):
if self.cov_controller is None:
return
if not (self.failed and self.options.no_cov_on_fail):
self.cov_controller.summary(terminalreporter._tw)
total = self.cov_controller.summary(terminalreporter._tw)
if total < self.options.cov_min:
raise CoverageError(('Required test coverage of %d%% not '
'reached. Total coverage: %.2f%%')
% (self.options.cov_min, total))

def pytest_runtest_setup(self, item):
if os.getpid() != self.pid: