Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e760099

Browse filesBrowse files
committed
Make sure the CLI precision is used when creating report. Fixes #674.
1 parent 44540e1 commit e760099
Copy full SHA for e760099

File tree

3 files changed

+44
-2
lines changed
Filter options

3 files changed

+44
-2
lines changed

‎src/pytest_cov/engine.py

Copy file name to clipboardExpand all lines: src/pytest_cov/engine.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,16 @@ def _data_suffix(name):
6767
class CovController:
6868
"""Base class for different plugin implementations."""
6969

70-
def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, config=None, nodeid=None):
70+
cov: coverage.Coverage | None
71+
72+
def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, cov_precision, config=None, nodeid=None):
7173
"""Get some common config used by multiple derived classes."""
7274
self.cov_source = cov_source
7375
self.cov_report = cov_report
7476
self.cov_config = cov_config
7577
self.cov_append = cov_append
7678
self.cov_branch = cov_branch
79+
self.cov_precision = cov_precision
7780
self.config = config
7881
self.nodeid = nodeid
7982

@@ -199,6 +202,7 @@ def summary(self, stream):
199202
'show_missing': ('term-missing' in self.cov_report) or None,
200203
'ignore_errors': True,
201204
'file': stream,
205+
'precision': self.cov_precision,
202206
}
203207
skip_covered = isinstance(self.cov_report, dict) and 'skip-covered' in self.cov_report.values()
204208
options.update({'skip_covered': skip_covered or None})

‎src/pytest_cov/plugin.py

Copy file name to clipboardExpand all lines: src/pytest_cov/plugin.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import warnings
66
from io import StringIO
77
from pathlib import Path
8+
from typing import TYPE_CHECKING
89

910
import coverage
1011
import pytest
@@ -16,6 +17,9 @@
1617
from . import compat
1718
from . import embed
1819

20+
if TYPE_CHECKING:
21+
from .engine import CovController
22+
1923

2024
def validate_report(arg):
2125
file_choices = ['annotate', 'html', 'xml', 'json', 'lcov']
@@ -239,7 +243,7 @@ def __init__(self, options, pluginmanager, start=True, no_cov_should_warn=False)
239243

240244
# worker is started in pytest hook
241245

242-
def start(self, controller_cls, config=None, nodeid=None):
246+
def start(self, controller_cls: 'CovController', config=None, nodeid=None):
243247
if config is None:
244248
# fake config option for engine
245249
class Config:
@@ -253,6 +257,7 @@ class Config:
253257
self.options.cov_config,
254258
self.options.cov_append,
255259
self.options.cov_branch,
260+
self.options.cov_precision,
256261
config,
257262
nodeid,
258263
)

‎tests/test_pytest_cov.py

Copy file name to clipboardExpand all lines: tests/test_pytest_cov.py
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,39 @@ def test_cov_min_float_value_not_reached_cli(testdir):
476476
result.stdout.fnmatch_lines(['FAIL Required test coverage of 88.89% not reached. Total coverage: 88.89%'])
477477

478478

479+
def test_cov_precision(testdir):
480+
script = testdir.makepyfile(SCRIPT)
481+
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-precision=6', script)
482+
assert result.ret == 0
483+
result.stdout.fnmatch_lines(
484+
[
485+
'Name Stmts Miss Cover Missing',
486+
'----------------------------------------------------------',
487+
'test_cov_precision.py 9 1 88.888889% 11',
488+
'----------------------------------------------------------',
489+
'TOTAL 9 1 88.888889%',
490+
]
491+
)
492+
493+
494+
def test_cov_precision_from_config(testdir):
495+
script = testdir.makepyfile(SCRIPT)
496+
testdir.tmpdir.join('pyproject.toml').write("""
497+
[tool.coverage.report]
498+
precision = 6""")
499+
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-report=term-missing', script)
500+
assert result.ret == 0
501+
result.stdout.fnmatch_lines(
502+
[
503+
'Name Stmts Miss Cover Missing',
504+
'----------------------------------------------------------------------',
505+
'test_cov_precision_from_config.py 9 1 88.888889% 11',
506+
'----------------------------------------------------------------------',
507+
'TOTAL 9 1 88.888889%',
508+
]
509+
)
510+
511+
479512
def test_cov_min_no_report(testdir):
480513
script = testdir.makepyfile(SCRIPT)
481514

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.