Python 在原始输入时进行鼻子测试冻结
我有一个nose测试,它导入一个文件,该文件运行一个带有原始输入的类。每当我在命令行中键入nosetests时,提示就会暂停,不再继续-我必须中断键盘以查看发生了什么,结果是nosetest正在运行我的文件,直到第一个原始输入(许多输入之一),此时它只是暂停,无法继续Python 在原始输入时进行鼻子测试冻结,python,nose,nosetests,raw-input,Python,Nose,Nosetests,Raw Input,我有一个nose测试,它导入一个文件,该文件运行一个带有原始输入的类。每当我在命令行中键入nosetests时,提示就会暂停,不再继续-我必须中断键盘以查看发生了什么,结果是nosetest正在运行我的文件,直到第一个原始输入(许多输入之一),此时它只是暂停,无法继续 有没有办法绕过这个?谢谢 如果可能,重写该文件,使其在导入时不会调用raw_input() # imported file if __name__ == "__main__": raw_input() 否则,如果您可以提
有没有办法绕过这个?谢谢 如果可能,重写该文件,使其在导入时不会调用raw_input()
# imported file
if __name__ == "__main__":
raw_input()
否则,如果您可以提前确定什么是可接受的输入,则可以从文件中获取标准输入。假设input.txt包含“Pass”:
或者,您可以将可接受的输入导入到测试中:
c:\>echo Pass | nosetests test_input.py
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
c:\>echo Fail | nosetests test_input.py
F
======================================================================
FAIL: cgp.test.test_input.test_input
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\nose\case.py", line 187, in runTest
self.test(*self.arg)
File "c:\test_input.py", line 3, in test_input
assert s.strip() == "Pass"
AssertionError
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (failures=1)
# test file
def test_input():
s = raw_input()
assert s.strip() == "Pass"
c:\>echo Pass | nosetests test_input.py
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
c:\>echo Fail | nosetests test_input.py
F
======================================================================
FAIL: cgp.test.test_input.test_input
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\nose\case.py", line 187, in runTest
self.test(*self.arg)
File "c:\test_input.py", line 3, in test_input
assert s.strip() == "Pass"
AssertionError
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (failures=1)