def test_funcarg_lookup_default(self, testdir): item = testdir.getitem("def test_func(some, other=42): pass") class Provider: def pytest_funcarg__some(self, request): return request.function.__name__ item.config.pluginmanager.register(Provider()) funcargs.fillfuncargs(item) assert len(item.funcargs) == 1
def test_funcarg_basic(self, testdir): item = testdir.getitem("def test_func(some, other): pass") class Provider: def pytest_funcarg__some(self, request): return request.function.__name__ def pytest_funcarg__other(self, request): return 42 item.config.pluginmanager.register(Provider()) funcargs.fillfuncargs(item) assert len(item.funcargs) == 2 assert item.funcargs['some'] == "test_func" assert item.funcargs['other'] == 42
def test_funcarg_lookup_modulelevel(self, testdir): modcol = testdir.getmodulecol(""" def pytest_funcarg__something(request): return request.function.__name__ class TestClass: def test_method(self, something): pass def test_func(something): pass """) item1, item2 = testdir.genitems([modcol]) funcargs.fillfuncargs(item1) assert item1.funcargs['something'] == "test_method" funcargs.fillfuncargs(item2) assert item2.funcargs['something'] == "test_func"
def setup(self): super(Function, self).setup() if hasattr(self, 'funcargs'): funcargs.fillfuncargs(self)