在使用pytest
运行特定的unittest
时,偶尔会出现这个错误(在标题中提到),从堆栈跟踪来看,它发生在以下代码行:
choice = input().lower()
当控制流到达此语句时,整个函数是:
def prompt_to_activate(bear, printer):
PROMPT_TO_ACTIVATE_STR = ('program has found {} to be useful '
'based of dependencies discovered from your '
'project files. \n Would you like to activate '
'it? (y/n)')
printer.print(PROMPT_TO_ACTIVATE_STR)
choice = input().lower()
if choice.startswith('y'):
return True
elif choice.startswith('n'):
return False
else:
return prompt_to_activate(bear, printer)
for i in range(0, 3):
a = i
print(a)
我尝试在这个语句之前添加一些 time.sleep(x)
,但这并没有解决问题。有人可以告诉我发生这种情况的确切原因以及如何解决吗?