Ish*_*ava 7 python unit-testing pytest python-unittest
在运行特定unittest用pytest,它偶尔失败,此错误(在标题中提到)和从堆栈跟踪它发生就行
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)
Run Code Online (Sandbox Code Playgroud)
我尝试time.sleep(x)在该语句之前添加一些内容,但这无法解决。有人可以告诉我发生这种情况的确切原因以及解决方法吗?
由于input()是一种交互式功能,您将需要在自动化测试中模拟返回值。像这样:
def test_prompt(capsys, monkeypatch):
monkeypatch.setattr('path.to.yourmodule.input', lambda: 'no')
val = prompt_to_activate(bear=..., printer=...)
assert not val
Run Code Online (Sandbox Code Playgroud)
小智 5
import ipdb; ipdb.set_trace()万一其他人偶然发现了这一点,如果您忘记了代码中的pdb 断点 ( ),也会引发此错误。
| 归档时间: |
|
| 查看次数: |
2446 次 |
| 最近记录: |