I'm currently using nose to perform some tests, and when using generators with nose+xunit output you need to set the current function's __name__
attribute to properly control the name of the test in the xunit output (see here for example).
Since I don't want to hard-code the name of the function each time like this:
def my_function():
for foo in bar:
fn = lambda: some_generated_test(foo)
fn.description = foo.get('name')
my_function.__name__ = foo.get('name')
yield fn
How can I programatically reference the function and set __name__
?
I had tried with sys._getframe()
which yields various properties about the current function (name etc), which I tried to use with setattr(*something*, "__name__", some_test_name)
, but that didn't work as I couldn't seem to work out which part of sys._getframe()
references the function.