Skip to content

Commit 08f1101

Browse files
committed
Add --cov-precision option. Close #655.
1 parent 76fe2a7 commit 08f1101

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/pytest_cov/plugin.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ def pytest_addoption(parser):
149149
default=None,
150150
help='Enable branch coverage.',
151151
)
152+
group.addoption(
153+
'--cov-precision',
154+
type=int,
155+
default=None,
156+
help='Override the reporting precision.',
157+
)
152158
group.addoption(
153159
'--cov-context',
154160
action='store',
@@ -257,7 +263,8 @@ class Config:
257263
cov_config = self.cov_controller.cov.config
258264
if self.options.cov_fail_under is None and hasattr(cov_config, 'fail_under'):
259265
self.options.cov_fail_under = cov_config.fail_under
260-
self.options.cov_precision = getattr(cov_config, 'precision', 0)
266+
if self.options.cov_precision is None:
267+
self.options.cov_precision = getattr(cov_config, 'precision', 0)
261268

262269
def _is_worker(self, session):
263270
return getattr(session.config, 'workerinput', None) is not None

tests/test_pytest_cov.py

+9
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,15 @@ def test_cov_min_float_value_not_reached(testdir):
467467
result.stdout.fnmatch_lines(['FAIL Required test coverage of 88.89% not reached. Total coverage: 88.89%'])
468468

469469

470+
def test_cov_min_float_value_not_reached_cli(testdir):
471+
script = testdir.makepyfile(SCRIPT)
472+
result = testdir.runpytest(
473+
'-v', f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-precision=3', '--cov-fail-under=88.89', script
474+
)
475+
assert result.ret == 1
476+
result.stdout.fnmatch_lines(['FAIL Required test coverage of 88.89% not reached. Total coverage: 88.89%'])
477+
478+
470479
def test_cov_min_no_report(testdir):
471480
script = testdir.makepyfile(SCRIPT)
472481

0 commit comments

Comments
 (0)