From 2cc4228e4b7543418d7e14d9eca66f7263870cf3 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 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'coverage/misc.py') 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): -- cgit v1.2.1