我希望拥有与执行os.system时相同的输出:
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)
我得到:
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)
您使用了错误的命令行。这是正确的:
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
以测试的名称结束(仔细阅读您得到的错误......