Skip to content

Commit 7ec98ba

Browse files
committed
Avoid importing coverage for test runs that don't need it
1 parent f1671be commit 7ec98ba

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/pytest_cov/plugin.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
import warnings
55

66
import pytest
7-
from coverage.misc import CoverageException
87

98
from . import compat
109
from . import embed
11-
from . import engine
1210

1311

1412
class CoverageError(Exception):
@@ -146,6 +144,10 @@ def __init__(self, options, pluginmanager, start=True):
146144
self.options.cov_report = {}
147145
self.options.cov_source = _prepare_cov_source(self.options.cov_source)
148146

147+
# import engine lazily here to avoid importing
148+
# it for unit tests that don't need it
149+
from . import engine
150+
149151
if is_dist and start:
150152
self.start(engine.DistMaster)
151153
elif start:
@@ -188,6 +190,10 @@ def pytest_sessionstart(self, session):
188190
self._disabled = True
189191
return
190192

193+
# import engine lazily here to avoid importing
194+
# it for unit tests that don't need it
195+
from . import engine
196+
191197
self.pid = os.getpid()
192198
if self._is_worker(session):
193199
nodeid = (
@@ -239,6 +245,11 @@ def pytest_runtestloop(self, session):
239245
self.cov_controller.finish()
240246

241247
if not self._is_worker(session) and self._should_report():
248+
249+
# import coverage lazily here to avoid importing
250+
# it for unit tests that don't need it
251+
from coverage.misc import CoverageException
252+
242253
try:
243254
self.cov_total = self.cov_controller.summary(self.cov_report)
244255
except CoverageException as exc:

0 commit comments

Comments
 (0)