def test_varnames(): def f(x): i = 3 class A: def f(self, y): pass class B(object): def __call__(self, z): pass assert varnames(f) == ("x",) assert varnames(A().f) == ('y',) assert varnames(B()) == ('z',)
def test_varnames(): def f(x): i = 3 class A: def f(self, y): pass class B(object): def __call__(self, z): pass assert varnames(f) == ("x", ) assert varnames(A().f) == ('y', ) assert varnames(B()) == ('z', )
def pytest_plugin_registered(manager, plugin): methods = collectattr(plugin) hooks = {} for hookspec in manager.hook._hookspecs: hooks.update(collectattr(hookspec)) stringio = py.io.TextIO() def Print(*args): if args: stringio.write(" ".join(map(str, args))) stringio.write("\n") fail = False while methods: name, method = methods.popitem() #print "checking", name if isgenerichook(name): continue if name not in hooks: if not getattr(method, 'optionalhook', False): Print("found unknown hook:", name) fail = True else: #print "checking", method method_args = list(varnames(method)) if '__multicall__' in method_args: method_args.remove('__multicall__') hook = hooks[name] hookargs = varnames(hook) for arg in method_args: if arg not in hookargs: Print("argument %r not available" % (arg, )) Print("actual definition: %s" % (formatdef(method))) Print("available hook arguments: %s" % ", ".join(hookargs)) fail = True break #if not fail: # print "matching hook:", formatdef(method) if fail: name = getattr(plugin, '__name__', plugin) raise PluginValidationError("%s:\n%s" % (name, stringio.getvalue()))
def pytest_plugin_registered(manager, plugin): methods = collectattr(plugin) hooks = {} for hookspec in manager.hook._hookspecs: hooks.update(collectattr(hookspec)) stringio = py.io.TextIO() def Print(*args): if args: stringio.write(" ".join(map(str, args))) stringio.write("\n") fail = False while methods: name, method = methods.popitem() #print "checking", name if isgenerichook(name): continue if name not in hooks: if not getattr(method, 'optionalhook', False): Print("found unknown hook:", name) fail = True else: #print "checking", method method_args = list(varnames(method)) if '__multicall__' in method_args: method_args.remove('__multicall__') hook = hooks[name] hookargs = varnames(hook) for arg in method_args: if arg not in hookargs: Print("argument %r not available" %(arg, )) Print("actual definition: %s" %(formatdef(method))) Print("available hook arguments: %s" % ", ".join(hookargs)) fail = True break #if not fail: # print "matching hook:", formatdef(method) if fail: name = getattr(plugin, '__name__', plugin) raise PluginValidationError("%s:\n%s" % (name, stringio.getvalue()))