相关疑难解决方法(0)

python模拟unittests中的原始输入

假设我有这个python代码:

def answer():
    ans = raw_input('enter yes or no')
    if ans == 'yes':
        print 'you entered yes'
    if ans == 'no':
        print 'you entered no'
Run Code Online (Sandbox Code Playgroud)

我该如何为此编写单元测试?我知道我必须使用'模拟',但我不明白如何.有谁可以做一些简单的例子?

python unit-testing mocking

33
推荐指数
4
解决办法
3万
查看次数

标签 统计

mocking ×1

python ×1

unit-testing ×1