summaryrefslogtreecommitdiff
path: root/coverage/misc.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-02-07 13:03:17 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-02-07 13:03:17 -0500
commitf0eb7f779f14cce5fc34581439c25cfa5c13d23a (patch)
tree1df490c2e650e0226c69732d3a0e5791a2bd80bd /coverage/misc.py
parentb42e55419aad9b0cc8dcb3a5056911a3b2df5b04 (diff)
downloadpython-coveragepy-f0eb7f779f14cce5fc34581439c25cfa5c13d23a.tar.gz
PyContracts need protection from metacov, centralize that too.
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 90988df..40a9f72 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.