summaryrefslogtreecommitdiff
path: root/coverage/misc.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2017-01-16 08:09:46 -0500
committerNed Batchelder <ned@nedbatchelder.com>2017-01-16 08:09:46 -0500
commit9fe048aab56d8dd4b856127f2734f6f159e18f41 (patch)
tree2f83314e61c2fd7b2dd66dd8bb541e1d24e12b77 /coverage/misc.py
parent5f5510fba829e12d57adb949667ce8e3c5ff09d9 (diff)
downloadpython-coveragepy-git-9fe048aab56d8dd4b856127f2734f6f159e18f41.tar.gz
A better way to neuter decorators when not testing.
Diffstat (limited to 'coverage/misc.py')
-rw-r--r--coverage/misc.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/coverage/misc.py b/coverage/misc.py
index e78a1537..797a16d5 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.