diff options
Diffstat (limited to 'coverage/misc.py')
-rw-r--r-- | coverage/misc.py | 23 |
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. |