2013-03-04 66 views
2

運行在使用子過程執行測試如下:子過程不捕獲從Django的所有標準輸出的測試用鼻

subprocess.Popen(["./manage.py", "test", "-x", "--settings=settings_test"], stdout=subprocess.PIPE, stdin=subprocess.PIPE).communicate() 

只有測試輸出的初始部分被捕獲。所以我得到返回的元組

("\x1b[32mUsing database: develop\x1b[0m\n\x1b[33mRunning tests against sqlite3 in memory database\x1b[0m\nnosetests --verbosity 1 -x\nCreating test database for alias 'default'...\nDestroying test database for alias 'default'...\n", None) 

然而,這忽略了關鍵的最後三線

Ran 260 tests in 70.131s 

OK (SKIP=1) 

有沒有辦法使用子捕獲該輸出?

回答

1

這是因爲總結被寫入stderr,所以你也需要知道。

sub = subprocess.Popen(
     ["./manage.py", "test", "-x", "--settings=settings_test"], 
     stdout=subprocess.PIPE, stderr=subprocess.PIPE) 
out, err = sub.communicate() 
# err should have the summary 
相關問題