Skip to content

Commit c2098df

Browse 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 b502063 commit c2098df

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/pytest_cov/engine.py

+8-7
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
@@ -69,14 +70,14 @@ class CovController:
6970

7071
cov: coverage.Coverage | None
7172

72-
def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, cov_precision, config=None, nodeid=None):
73+
def __init__(self, options: argparse.Namespace, config: None | object, nodeid: None | str):
7374
"""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
75+
self.cov_source = options.cov_source
76+
self.cov_report = options.cov_report
77+
self.cov_config = options.cov_config
78+
self.cov_append = options.cov_append
79+
self.cov_branch = options.cov_branch
80+
self.cov_precision = options.cov_precision
8081
self.config = config
8182
self.nodeid = nodeid
8283

src/pytest_cov/plugin.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class CovPlugin:
202202
distributed worker.
203203
"""
204204

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

245245
# worker is started in pytest hook
246246

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

253253
config = Config()
254254

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

0 commit comments

Comments
 (0)