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 aa57aed

Browse filesBrowse files
committed
Refactor a bit the internals to be a bit less boilerplatey and have more clarity. The config/nodeid were never meant to be optional for this internal class - the intention there was to signal that they can be None values.
1 parent e760099 commit aa57aed
Copy full SHA for aa57aed

File tree

2 files changed

+12
-21
lines changed
Filter options

2 files changed

+12
-21
lines changed

‎src/pytest_cov/engine.py

Copy file name to clipboardExpand all lines: src/pytest_cov/engine.py
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Coverage controllers for use by pytest-cov and nose-cov."""
22

3+
import argparse
34
import contextlib
45
import copy
56
import functools
@@ -11,6 +12,7 @@
1112
import warnings
1213
from io import StringIO
1314
from pathlib import Path
15+
from typing import Union
1416

1517
import coverage
1618
from coverage.data import CoverageData
@@ -67,16 +69,14 @@ def _data_suffix(name):
6769
class CovController:
6870
"""Base class for different plugin implementations."""
6971

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):
72+
def __init__(self, options: argparse.Namespace, config: Union[None, object], nodeid: Union[None, str]):
7373
"""Get some common config used by multiple derived classes."""
74-
self.cov_source = cov_source
75-
self.cov_report = cov_report
76-
self.cov_config = cov_config
77-
self.cov_append = cov_append
78-
self.cov_branch = cov_branch
79-
self.cov_precision = cov_precision
74+
self.cov_source = options.cov_source
75+
self.cov_report = options.cov_report
76+
self.cov_config = options.cov_config
77+
self.cov_append = options.cov_append
78+
self.cov_branch = options.cov_branch
79+
self.cov_precision = options.cov_precision
8080
self.config = config
8181
self.nodeid = nodeid
8282

‎src/pytest_cov/plugin.py

Copy file name to clipboardExpand all lines: src/pytest_cov/plugin.py
+3-12Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class CovPlugin:
201201
distributed worker.
202202
"""
203203

204-
def __init__(self, options, pluginmanager, start=True, no_cov_should_warn=False):
204+
def __init__(self, options: argparse.Namespace, pluginmanager, start=True, no_cov_should_warn=False):
205205
"""Creates a coverage pytest plugin.
206206
207207
We read the rc file that coverage uses to get the data file
@@ -243,24 +243,15 @@ def __init__(self, options, pluginmanager, start=True, no_cov_should_warn=False)
243243

244244
# worker is started in pytest hook
245245

246-
def start(self, controller_cls: 'CovController', config=None, nodeid=None):
246+
def start(self, controller_cls: type['CovController'], config=None, nodeid=None):
247247
if config is None:
248248
# fake config option for engine
249249
class Config:
250250
option = self.options
251251

252252
config = Config()
253253

254-
self.cov_controller = controller_cls(
255-
self.options.cov_source,
256-
self.options.cov_report,
257-
self.options.cov_config,
258-
self.options.cov_append,
259-
self.options.cov_branch,
260-
self.options.cov_precision,
261-
config,
262-
nodeid,
263-
)
254+
self.cov_controller = controller_cls(self.options, config, nodeid)
264255
self.cov_controller.start()
265256
self._started = True
266257
self._start_path = Path.cwd()

0 commit comments

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