Skip to content
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

Remove deprecated pytest-coverage scope in favor of coverage-py #10103

Merged
merged 1 commit into from Jun 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 5 additions & 26 deletions src/python/pants/backend/python/rules/coverage.py
Expand Up @@ -21,7 +21,6 @@
from pants.backend.python.subsystems.python_tool_base import PythonToolBase
from pants.backend.python.subsystems.subprocess_environment import SubprocessEncodingEnvironment
from pants.backend.python.target_types import PythonSources, PythonTestsSources
from pants.base.deprecated import resolve_conflicting_options
from pants.core.goals.test import (
ConsoleCoverageReport,
CoverageData,
Expand Down Expand Up @@ -52,13 +51,12 @@
Step 1: Run each test with the appropriate `--cov` arguments.
In `python_test_runner.py`, we pass options so that the pytest-cov plugin runs and records which
lines were encountered in the test. For each test, it will save a `.coverage` file (SQLite DB
format). The files stored in `.coverage` will be stripped of source roots. We load up our custom
Pants coverage plugin, but the plugin doesn't actually do anything yet. We only load our plugin
because Coverage expects to find the plugin in the `.coverage` file in the later steps.
format). The files stored in `.coverage` will be stripped of source roots. Our plugin records which
files are "owned" by the plugin.

Step 2: Merge the results with `coverage combine`.
We now have a bunch of individual `PytestCoverageData` values. We run `coverage combine` to convert
this into a single `.coverage` file.
We now have a bunch of individual `PytestCoverageData` values, each with their own `.coverage` file.
We run `coverage combine` to convert this into a single `.coverage` file.

Step 3: Generate the report with `coverage {html,xml,console}`.
All the files in the single merged `.coverage` file are still stripped, and we want to generate a
Expand All @@ -77,8 +75,6 @@ class CoverageSubsystem(PythonToolBase):
default_version = "coverage>=5.0.3,<5.1"
default_entry_point = "coverage"
default_interpreter_constraints = ["CPython>=3.6"]
deprecated_options_scope = "pytest-coverage"
deprecated_options_scope_removal_version = "1.31.0.dev0"

@classmethod
def register_options(cls, register):
Expand Down Expand Up @@ -111,15 +107,6 @@ def register_options(cls, register):
advanced=True,
help="Path to write the Pytest Coverage report to. Must be relative to build root.",
)
register(
"--report-output-path",
type=str,
default=PurePath("dist", "coverage", "python").as_posix(),
removal_version="1.31.0.dev0",
removal_hint="Use `output_dir` in the `[pytest-cov]` scope instead",
advanced=True,
help="Path to write pytest coverage report to. Must be relative to build root.",
)
register(
"--omit-test-sources",
type=bool,
Expand All @@ -138,15 +125,7 @@ def report(self) -> CoverageReportType:

@property
def output_dir(self) -> PurePath:
output_dir = resolve_conflicting_options(
old_scope="pytest-coverage",
new_scope="pytest-cov",
old_option="report_output_path",
new_option="output_dir",
old_container=self.options,
new_container=self.options,
)
return PurePath(output_dir)
return PurePath(self.options.output_dir)

@property
def omit_test_sources(self) -> bool:
Expand Down