我可以从python测试函数的名称中删除下划线

时间:2014-10-27 13:00:30

标签: python

我有两个长名称的函数:

# 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中是否有类似的构造?

1 个答案:

答案 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命名约束,这个函数的新名称应该是正确的,例如没有空格

相关问题