我有两个长名称的函数:
# ruby
def test_write_method_raises_value_error
# python
def test_write_method_raises_value_error(self):
在ruby中我可以rename
函数如下:
test 'write method should raise value error' do
# rest of function
Python中是否有类似的构造?
答案 0 :(得分:1)
如果您只是为了测试目的而需要缩短功能名称,则可以轻松完成。
一切都是python中的对象,甚至是函数。你可以将它分配给变量,实际上只是一个标签。
例如:
def very_very_long_function_name_that_we_want_to_test(argument):
pass
# test:
testable = very_very_long_function_name_that_we_want_to_test
# This will call our "long function"
testable('test')
但是根据Python命名约束,这个函数的新名称应该是正确的,例如没有空格