Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,16 @@ def _data_suffix(name):
class CovController:
"""Base class for different plugin implementations."""

def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, config=None, nodeid=None):
cov: coverage.Coverage | None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps move this into the initializer? Any reason to have it right here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a type annotation - ":" doesn't assign anything to the "cov" class attribute. I added it mostly to make some things easier in my editor.


def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, cov_precision, config=None, nodeid=None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably best to make the new arg last + maybe kw-only so that it isn't a breaking change in the signature.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well now that you mention it, it does look odd doesn't it. Such a large number of positional always leads to some trouble. Funny thing, the config and nodeid are always passed. It was like that since the first commit where this was set to be a common lib for both pytest and nose: 7c6448d

"""Get some common config used by multiple derived classes."""
self.cov_source = cov_source
self.cov_report = cov_report
self.cov_config = cov_config
self.cov_append = cov_append
self.cov_branch = cov_branch
self.cov_precision = cov_precision
self.config = config
self.nodeid = nodeid

Expand Down Expand Up @@ -199,6 +202,7 @@ def summary(self, stream):
'show_missing': ('term-missing' in self.cov_report) or None,
'ignore_errors': True,
'file': stream,
'precision': self.cov_precision,
}
skip_covered = isinstance(self.cov_report, dict) and 'skip-covered' in self.cov_report.values()
options.update({'skip_covered': skip_covered or None})
Expand Down
7 changes: 6 additions & 1 deletion src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import warnings
from io import StringIO
from pathlib import Path
from typing import TYPE_CHECKING

import coverage
import pytest
Expand All @@ -17,6 +18,9 @@
from . import compat
from . import embed

if TYPE_CHECKING:
from .engine import CovController


def validate_report(arg):
file_choices = ['annotate', 'html', 'xml', 'json', 'lcov']
Expand Down Expand Up @@ -240,7 +244,7 @@ def __init__(self, options, pluginmanager, start=True, no_cov_should_warn=False)

# worker is started in pytest hook

def start(self, controller_cls, config=None, nodeid=None):
def start(self, controller_cls: 'CovController', config=None, nodeid=None):
if config is None:
# fake config option for engine
class Config:
Expand All @@ -254,6 +258,7 @@ class Config:
self.options.cov_config,
self.options.cov_append,
self.options.cov_branch,
self.options.cov_precision,
config,
nodeid,
)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,39 @@ def test_cov_min_float_value_not_reached_cli(testdir):
result.stdout.fnmatch_lines(['FAIL Required test coverage of 88.89% not reached. Total coverage: 88.89%'])


def test_cov_precision(testdir):
script = testdir.makepyfile(SCRIPT)
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-report=term-missing', '--cov-precision=6', script)
assert result.ret == 0
result.stdout.fnmatch_lines(
[
'Name Stmts Miss Cover Missing',
'----------------------------------------------------------',
'test_cov_precision.py 9 1 88.888889% 11',
'----------------------------------------------------------',
'TOTAL 9 1 88.888889%',
]
)


def test_cov_precision_from_config(testdir):
script = testdir.makepyfile(SCRIPT)
testdir.tmpdir.join('pyproject.toml').write("""
[tool.coverage.report]
precision = 6""")
result = testdir.runpytest('-v', f'--cov={script.dirpath()}', '--cov-report=term-missing', script)
assert result.ret == 0
result.stdout.fnmatch_lines(
[
'Name Stmts Miss Cover Missing',
'----------------------------------------------------------------------',
'test_cov_precision_from_config.py 9 1 88.888889% 11',
'----------------------------------------------------------------------',
'TOTAL 9 1 88.888889%',
]
)


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

Expand Down
Loading