我想为我的命令行界面创建单元测试
使用Pythonprompt-toolkit
(https://github.com/jonathanslenders/python-prompt-toolkit)构建。在
示例代码:
from os import path
from prompt_toolkit import prompt
def csv():
csv_path = prompt('\nselect csv> ')
full_path = path.abspath(csv_path)
return full_path
您可以mock调用提示。在
应用程序文件
测试应用程序文件
^{pr2}$只需注意一点,您应该模仿中的提示应用程序副本,而不是来自prompt_toolkit,因为您想拦截来自文件的调用。在
根据docstring module:
正如method docstring所说:
在项目中的Getting started之后:
当
prompt
方法返回字符串类型时,可以使用mock.return_value
来模拟用户与应用程序的集成。在相关问题 更多 >
编程相关推荐