summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-07-23 07:35:28 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-07-23 07:35:28 -0400
commit2cc4228e4b7543418d7e14d9eca66f7263870cf3 (patch)
tree3fa2d95c6153276eaf95e01e4d5b2e27fa6f7d1b
parentb5d3a77d238c98ae85339e4c443627b60ddc4235 (diff)
downloadpython-coveragepy-git-2cc4228e4b7543418d7e14d9eca66f7263870cf3.tar.gz
Make sure env.TESTING is true during meta-coverage.
-rw-r--r--coverage/misc.py16
-rw-r--r--igor.py3
-rw-r--r--metacov.ini1
3 files changed, 14 insertions, 6 deletions
diff --git a/coverage/misc.py b/coverage/misc.py
index b99fbb81..6b7321da 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -15,12 +15,16 @@ if env.TESTING:
from contracts import contract # pylint: disable=unused-import
from contracts import new_contract
- # Define contract words that PyContract doesn't have.
- new_contract('bytes', lambda v: isinstance(v, bytes))
- if env.PY3:
- new_contract('unicode', lambda v: isinstance(v, unicode_class))
-
-else:
+ try:
+ # Define contract words that PyContract doesn't have.
+ new_contract('bytes', lambda v: isinstance(v, bytes))
+ if env.PY3:
+ new_contract('unicode', lambda v: isinstance(v, unicode_class))
+ except ValueError:
+ # During meta-coverage, this module is imported twice, and PyContracts
+ # doesn't like redefining contracts. It's OK.
+ pass
+else: # pragma: not covered
# We aren't using real PyContracts, so just define a no-op decorator as a
# stunt double.
def contract(**unused):
diff --git a/igor.py b/igor.py
index b3265fda..641d0b80 100644
--- a/igor.py
+++ b/igor.py
@@ -84,6 +84,9 @@ def run_tests(tracer, *nose_args):
def run_tests_with_coverage(tracer, *nose_args):
"""Run tests, but with coverage."""
+ # Need to define this early enough that the first import of env.py sees it.
+ os.environ['COVERAGE_TESTING'] = "True"
+
import coverage
os.environ['COVERAGE_PROCESS_START'] = os.path.abspath('metacov.ini')
diff --git a/metacov.ini b/metacov.ini
index b7573a10..061b7886 100644
--- a/metacov.ini
+++ b/metacov.ini
@@ -20,6 +20,7 @@ exclude_lines =
partial_branches =
# pragma: part covered
+ if env.TESTING:
ignore_errors = true
precision = 1