|
8 | 8 | from contextlib import contextmanager |
9 | 9 | from functools import partial |
10 | 10 |
|
11 | | -import coverage |
12 | 11 | import pytest |
13 | 12 | import six |
14 | 13 |
|
@@ -236,28 +235,31 @@ def no_coverage(): |
236 | 235 | pass |
237 | 236 |
|
238 | 237 |
|
239 | | -class EnableCoverage(object): |
240 | | - _COV_FILE = Path(coverage.__file__) |
241 | | - _ROOT_COV_FILES_AND_FOLDERS = [i for i in _COV_FILE.parents[1].iterdir() if i.name.startswith("coverage")] |
242 | | - |
243 | | - def __init__(self, link): |
244 | | - self.link = link |
245 | | - self.targets = [] |
246 | | - |
247 | | - def __enter__(self, creator): |
248 | | - site_packages = creator.purelib |
249 | | - for entry in self._ROOT_COV_FILES_AND_FOLDERS: |
250 | | - target = site_packages / entry.name |
251 | | - if not target.exists(): |
252 | | - clean = self.link(entry, target) |
253 | | - self.targets.append((target, clean)) |
254 | | - return self |
255 | | - |
256 | | - def __exit__(self, exc_type, exc_val, exc_tb): |
257 | | - for target, clean in self.targets: |
258 | | - if target.exists(): |
259 | | - clean() |
260 | | - assert self._COV_FILE.exists() |
| 238 | +if COVERAGE_RUN: |
| 239 | + import coverage |
| 240 | + |
| 241 | + class EnableCoverage(object): |
| 242 | + _COV_FILE = Path(coverage.__file__) |
| 243 | + _ROOT_COV_FILES_AND_FOLDERS = [i for i in _COV_FILE.parents[1].iterdir() if i.name.startswith("coverage")] |
| 244 | + |
| 245 | + def __init__(self, link): |
| 246 | + self.link = link |
| 247 | + self.targets = [] |
| 248 | + |
| 249 | + def __enter__(self, creator): |
| 250 | + site_packages = creator.purelib |
| 251 | + for entry in self._ROOT_COV_FILES_AND_FOLDERS: |
| 252 | + target = site_packages / entry.name |
| 253 | + if not target.exists(): |
| 254 | + clean = self.link(entry, target) |
| 255 | + self.targets.append((target, clean)) |
| 256 | + return self |
| 257 | + |
| 258 | + def __exit__(self, exc_type, exc_val, exc_tb): |
| 259 | + for target, clean in self.targets: |
| 260 | + if target.exists(): |
| 261 | + clean() |
| 262 | + assert self._COV_FILE.exists() |
261 | 263 |
|
262 | 264 |
|
263 | 265 | @pytest.fixture(scope="session") |
|
0 commit comments