Skip to content

Commit

Permalink
Avoid importing coverage for test runs that don't need it
Browse files Browse the repository at this point in the history
  • Loading branch information
boxed committed Sep 16, 2019
1 parent f1671be commit 7ec98ba
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/pytest_cov/plugin.py
Expand Up @@ -4,11 +4,9 @@
import warnings

import pytest
from coverage.misc import CoverageException

from . import compat
from . import embed
from . import engine


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

# import engine lazily here to avoid importing
# it for unit tests that don't need it
from . import engine

if is_dist and start:
self.start(engine.DistMaster)
elif start:
Expand Down Expand Up @@ -188,6 +190,10 @@ def pytest_sessionstart(self, session):
self._disabled = True
return

# import engine lazily here to avoid importing
# it for unit tests that don't need it
from . import engine

self.pid = os.getpid()
if self._is_worker(session):
nodeid = (
Expand Down Expand Up @@ -239,6 +245,11 @@ def pytest_runtestloop(self, session):
self.cov_controller.finish()

if not self._is_worker(session) and self._should_report():

# import coverage lazily here to avoid importing
# it for unit tests that don't need it
from coverage.misc import CoverageException

try:
self.cov_total = self.cov_controller.summary(self.cov_report)
except CoverageException as exc:
Expand Down

0 comments on commit 7ec98ba

Please sign in to comment.