summaryrefslogtreecommitdiff
path: root/coverage/misc.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/misc.py')
-rw-r--r--coverage/misc.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/coverage/misc.py b/coverage/misc.py
index 90988dfc..40a9f72c 100644
--- a/coverage/misc.py
+++ b/coverage/misc.py
@@ -42,17 +42,20 @@ os = isolate_module(os)
# we are running our own test suite.
if env.TESTING:
from contracts import contract # pylint: disable=unused-import
- from contracts import new_contract
+ from contracts import new_contract as raw_new_contract
- 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
+ def new_contract(*args, **kwargs):
+ try:
+ return raw_new_contract(*args, **kwargs)
+ except ValueError:
+ # During meta-coverage, this module is imported twice, and
+ # PyContracts doesn't like redefining contracts. It's OK.
+ pass
+
+ # 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: # pragma: not covered
# We aren't using real PyContracts, so just define a no-op decorator as a
# stunt double.