Skip to content

Commit bc493ee

Browse files
boxedionelmc
authored andcommitted
Avoid importing coverage for test runs that don't need it
1 parent bcf9865 commit bc493ee

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/pytest_cov/plugin.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
import coverage
77
import pytest
8-
from coverage.misc import CoverageException
98

109
from . import compat
1110
from . import embed
12-
from . import engine
1311

1412
PYTEST_VERSION = tuple(map(int, pytest.__version__.split('.')[:3]))
1513

@@ -160,6 +158,10 @@ def __init__(self, options, pluginmanager, start=True):
160158
self.options.cov_report = {}
161159
self.options.cov_source = _prepare_cov_source(self.options.cov_source)
162160

161+
# import engine lazily here to avoid importing
162+
# it for unit tests that don't need it
163+
from . import engine
164+
163165
if is_dist and start:
164166
self.start(engine.DistMaster)
165167
elif start:
@@ -202,6 +204,10 @@ def pytest_sessionstart(self, session):
202204
self._disabled = True
203205
return
204206

207+
# import engine lazily here to avoid importing
208+
# it for unit tests that don't need it
209+
from . import engine
210+
205211
self.pid = os.getpid()
206212
if self._is_worker(session):
207213
nodeid = (
@@ -256,6 +262,11 @@ def pytest_runtestloop(self, session):
256262
self.cov_controller.finish()
257263

258264
if not self._is_worker(session) and self._should_report():
265+
266+
# import coverage lazily here to avoid importing
267+
# it for unit tests that don't need it
268+
from coverage.misc import CoverageException
269+
259270
try:
260271
self.cov_total = self.cov_controller.summary(self.cov_report)
261272
except CoverageException as exc:

0 commit comments

Comments
 (0)