运行 Django 测试时如何查看标准输出? [英] How do I see stdout when running Django tests?
问题描述
当我使用 ./manage.py test
运行测试时,我通过 print
发送到标准输出的任何内容都不会显示.当测试失败时,我会看到每个失败的测试都有一个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 的项目特定运行器.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
首先捕获它并抛出no such option"错误.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 测试 -- -s
它忽略 -s
并让我在自定义跑步者的一侧捕获它,将其毫无问题地传递给 Nose.
it ignores the -s
and lets me capture it on the custom runner's side, passing it to Nose without a problem.
这篇关于运行 Django 测试时如何查看标准输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!