From ddb83b43a2794b47b60ab5956297df0cc45d22a5 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Thu, 23 Jul 2015 07:35:28 -0400 Subject: Make sure env.TESTING is true during meta-coverage. --- coverage/misc.py | 16 ++++++++++------ igor.py | 3 +++ metacov.ini | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/coverage/misc.py b/coverage/misc.py index b99fbb8..6b7321d 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 b3265fd..641d0b8 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 b7573a1..061b788 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 -- cgit v1.2.1