文档测试中的多行列表输出



我正在测试一个函数的结果,该函数返回一个长字符串列表。由于我有行大小限制,因此我不能将整个列表放在一行上。

我已经尝试打印列表并且有效,但我想知道是否有另一种方法而无需打印函数的结果。我得到了什么:

def my_function(input):
r"""Some description.
>>> import pprint
>>> pprint.pprint(my_function("input"))
['long_string_1',
'long_string_2',
'long_string_3']
"""
return list_of_long_strings

是否可以在不打印的情况下执行此操作,只需调用函数并具有带有反弹或其他内容的列表?

你可以这样做

def my_function(input):
r"""Some description.
>>> my_function("input") == ['long_string_1',
...     'long_string_2', 'long_string_3']
True
"""
list_of_long_strings = ['long_string_1', 'long_string_2', 'long_string_3']
return list_of_long_strings

最新更新