2014-01-14 90 views
0

我想有,當我執行使用os.system,我得到了相同的輸出:ValueError異常使用nosetest子

os.system('nosetests TestStateMachine.py:FluidityTest.test_it_has_an_initial_state -v') 
test_it_has_an_initial_state (TestStateMachine.FluidityTest) ... ok 

---------------------------------------------------------------------- 
Ran 1 test in 0.001s 

OK 
Out[5]: 0 

但是,當我執行:

x = subprocess.Popen(["nosetests", 
"TestStateMachine.py:FluidityTest.test_it_has_an_initial_state -v"], 
stdout=subprocess.PIPE) 

我m得到:

E 
====================================================================== 
ERROR: Failure: ValueError (No such test FluidityTest.test_it_has_an_initial_state -v) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
File "/usr/local/lib/python2.7/dist-packages/nose/failure.py", line 41, in runTest 
raise self.exc_class(self.exc_val) 
ValueError: No such test FluidityTest.test_it_has_an_initial_state -v 

---------------------------------------------------------------------- 
Ran 1 test in 0.034s 

FAILED (errors=1) 

回答

2

您正在使用錯誤的命令行。下面是正確的:

x = subprocess.Popen(["nosetests", 
    "TestStateMachine.py:FluidityTest.test_it_has_an_initial_state", 
    "-v"], 
    stdout=subprocess.PIPE) 

傳遞給Popen名單已經表示解析命令行。通過將測試的名稱和它就像相同的字符串的-v如果你引述他們,像做:

$nosetests "TestStateMachine.py:FluidityTest.test_it_has_an_initial_state -v" 

在命令行和-v在測試的名稱結束了(請仔細閱讀錯誤你得...)