运行Django测试时如何看到stdout? [英] How do I see stdout when running Django tests?
问题描述
当我使用 ./ manage.py test
运行测试时,无论通过打印发送到标准输出
不显示。当测试失败时,我会看到每个失败测试的stdout块,所以我猜Django陷阱它(但是当测试通过时不显示)。
When I run tests with ./manage.py test
, whatever I send to the standard output through print
doesn't show. When tests fail, I see an "stdout" block per failed test, so I guess Django traps it (but doesn't show it when tests pass).
推荐答案
在 settings.py
中检查 TEST_RUNNER
,它正在使用一个项目特定的运行程序出鼻子。 Nose具有 -s
选项以阻止它捕获 stdout
,但如果我运行:
Checked TEST_RUNNER
in settings.py
, it's using a project-specific runner that calls out to Nose. Nose has the -s
option to stop it from capturing stdout
, but if I run:
./ manage.py test -s
manage.py
首先捕获它并抛出一个不这样的选项错误。 manage.py
的帮助没有提到这一点,但是我发现如果我运行:
manage.py
captures it first and throws a "no such option" error. The help for manage.py
doesn't mention this, but I found that if I run:
./ manage.py test - -s
它忽略 -s
,让我在自定义赛跑者身上抓住它,将其传递给鼻子,没有问题。
it ignores the -s
and lets me capture it on the custom runner's side, passing it to Nose without a problem.
这篇关于运行Django测试时如何看到stdout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!