I use this decorator in unittest modules to verify that a particularly-named object exists:
def existsin(namespace):
"""Given a namespace, this decorator asserts that an object with
the same name as the function it's wrapping (minus ) exists in that
namespace"""
def wrapper(namedunittest):
assert namedunittest.__name__.startswith('test_'), \
"The wrapped '%s' function doesn't look like a unit test" % namedunittest.__name__