diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-16 08:09:46 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2017-01-16 08:09:46 -0500 |
commit | 3c96468c4f4192e4fe002b9b069d1fdd7e96955a (patch) | |
tree | 8ae246c1dde5e3d82f02b2b6d0a916ea368623e8 /coverage/misc.py | |
parent | bdab4fa31dd367105f746ec972cd95de8c99eaef (diff) | |
download | python-coveragepy-3c96468c4f4192e4fe002b9b069d1fdd7e96955a.tar.gz |
A better way to neuter decorators when not testing.
Diffstat (limited to 'coverage/misc.py')
-rw-r--r-- | coverage/misc.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/coverage/misc.py b/coverage/misc.py index e78a153..797a16d 100644 --- a/coverage/misc.py +++ b/coverage/misc.py @@ -39,6 +39,13 @@ def isolate_module(mod): os = isolate_module(os) +def dummy_decorator_with_args(*args_unused, **kwargs_unused): + """Dummy no-op implementation of a decorator with arguments.""" + def _decorator(func): + return func + return _decorator + + # Use PyContracts for assertion testing on parameters and returns, but only if # we are running our own test suite. if env.TESTING: @@ -70,22 +77,15 @@ if env.TESTING: return _wrapped return _decorator else: # pragma: not covered - # We aren't using real PyContracts, so just define a no-op decorator as a - # stunt double. - def contract(**unused): - """Dummy no-op implementation of `contract`.""" - return lambda func: func + # We aren't using real PyContracts, so just define our decorators as + # stunt-double no-ops. + contract = dummy_decorator_with_args + one_of = dummy_decorator_with_args def new_contract(*args_unused, **kwargs_unused): """Dummy no-op implementation of `new_contract`.""" pass - def one_of(argnames_unused): - """Dummy no-op implementation of `one_of`.""" - def _decorator(func): - return func - return _decorator - def nice_pair(pair): """Make a nice string representation of a pair of numbers. |