Skip to content

Commit

Permalink
Add --cov-precision option. Close #655.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Oct 29, 2024
1 parent 76fe2a7 commit 08f1101
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def pytest_addoption(parser):
default=None,
help='Enable branch coverage.',
)
group.addoption(
'--cov-precision',
type=int,
default=None,
help='Override the reporting precision.',
)
group.addoption(
'--cov-context',
action='store',
Expand Down Expand Up @@ -257,7 +263,8 @@ class Config:
cov_config = self.cov_controller.cov.config
if self.options.cov_fail_under is None and hasattr(cov_config, 'fail_under'):
self.options.cov_fail_under = cov_config.fail_under
self.options.cov_precision = getattr(cov_config, 'precision', 0)
if self.options.cov_precision is None:
self.options.cov_precision = getattr(cov_config, 'precision', 0)

def _is_worker(self, session):
return getattr(session.config, 'workerinput', None) is not None
Expand Down
9 changes: 9 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,15 @@ def test_cov_min_float_value_not_reached(testdir):
result.stdout.fnmatch_lines(['FAIL Required test coverage of 88.89% not reached. Total coverage: 88.89%'])


def test_cov_min_float_value_not_reached_cli(testdir):
script = testdir.makepyfile(SCRIPT)
result = testdir.runpytest(
'-v', f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-precision=3', '--cov-fail-under=88.89', script
)
assert result.ret == 1
result.stdout.fnmatch_lines(['FAIL Required test coverage of 88.89% not reached. Total coverage: 88.89%'])


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

Expand Down

0 comments on commit 08f1101

Please sign in to comment.