I would like to modify the testcase name that outputs when running my tests using the XMLTestrunner. The reason I need to do this is that I have some scenarios where when a particular test is being executed, I want it to report that another test name has passed because the functionality is the same. So all I want to change is the test name, nothing else. I've written a decorator to change the test name(function name) but when the test result is displayed, it still displays the old test name in the test report. See samples of python code below; I also tried assigning func.name = testcase in the decorator but that didn't help. The function name is actually changed but I'm not sure how to make xmlrunner take this instead.
decorator
def testcase(testname):
def decorator(func):
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
wrapper.__name__ = testname
wrapper.__dict__ = func.__dict__
wrapper.__doc__ = func.__doc__
return wrapper
return decorator
Test case
class MyTestClass(unittest.Testcase):
def setUp():
...
def tearDown():
...
@testcase('new_test_name')
def_test_old_test_name(self):
#do the same thing
if __name__ == "__main__":
unittest.main(testRunner=xmlRunner.XMLTestRunner(out='reports'))
Aucun commentaire:
Enregistrer un commentaire