Skip to content

Commit

Permalink
conftest.py: Make coverage optional (#2008)
Browse files Browse the repository at this point in the history
This allows to execute the tests without coverage installed.
We plan to do that in Fedora, where we run the tests, but not measure coverage.
  • Loading branch information
hroncok authored Nov 21, 2020
1 parent 271dd73 commit ed7ceb5
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from contextlib import contextmanager
from functools import partial

import coverage
import pytest
import six

Expand Down Expand Up @@ -236,28 +235,31 @@ def no_coverage():
pass


class EnableCoverage(object):
_COV_FILE = Path(coverage.__file__)
_ROOT_COV_FILES_AND_FOLDERS = [i for i in _COV_FILE.parents[1].iterdir() if i.name.startswith("coverage")]

def __init__(self, link):
self.link = link
self.targets = []

def __enter__(self, creator):
site_packages = creator.purelib
for entry in self._ROOT_COV_FILES_AND_FOLDERS:
target = site_packages / entry.name
if not target.exists():
clean = self.link(entry, target)
self.targets.append((target, clean))
return self

def __exit__(self, exc_type, exc_val, exc_tb):
for target, clean in self.targets:
if target.exists():
clean()
assert self._COV_FILE.exists()
if COVERAGE_RUN:
import coverage

class EnableCoverage(object):
_COV_FILE = Path(coverage.__file__)
_ROOT_COV_FILES_AND_FOLDERS = [i for i in _COV_FILE.parents[1].iterdir() if i.name.startswith("coverage")]

def __init__(self, link):
self.link = link
self.targets = []

def __enter__(self, creator):
site_packages = creator.purelib
for entry in self._ROOT_COV_FILES_AND_FOLDERS:
target = site_packages / entry.name
if not target.exists():
clean = self.link(entry, target)
self.targets.append((target, clean))
return self

def __exit__(self, exc_type, exc_val, exc_tb):
for target, clean in self.targets:
if target.exists():
clean()
assert self._COV_FILE.exists()


@pytest.fixture(scope="session")
Expand Down

0 comments on commit ed7ceb5

Please sign in to comment.