Is it possible to rename method in Python?
Something like this
class Validation(unittest.TestCase):
def __init__(self, methodName='runTest'):
super(Validation, self).__init__(methodName)
#Doesn't work
setattr(self,'do_folders_equal','test_do_folders_equal')
Rename method ‘do_folders_equal’ to ‘test_do_folders_equal’..
Usage above , obviously, is incorrect…How to do this hack?
You wouldn’t rename it, you’d just assign it to another variable:
class Validation(unittest.TestCase):
However there can sometimes be some weird interplay with inherited methods etc, so it sort of depends what you are trying to do. Not sure how this behaves on old-style classes either…
EDIT: Or using a name read at runtime:
class Validation(unittest.TestCase):