子进程没有捕获来自Django测试的所有stdout与Nose一起运行

时间:2013-03-04 14:02:15

标签: python django testing subprocess nose

使用子进程执行测试时如下:

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 个答案:

答案 0 :(得分: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