在运行Django测试时,我如何看到stdout ?

时间:2021-04-09 00:03:20

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).

当我运行测试时。/管理。py测试,我通过print发送到标准输出的任何内容都没有显示出来。当测试失败时,我看到每个失败的测试都有一个“stdout”块,因此我猜想Django会捕获它(但是在测试通过时不会显示它)。

4 个解决方案

#1


32  

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:

检查TEST_RUNNER设置。py,它使用了一个项目专用的跑步者来呼叫鼻子。Nose有-s选项可以阻止它捕获stdout,但是如果我运行:

./manage.py test -s

/管理。py - s测试

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:

管理。py首先捕获它并抛出一个“没有这样的选项”错误。帮助管理。py没有提到这个,但是我发现如果我跑:

./manage.py test -- -s

/管理。py测试——- s

it ignores the -s and lets me capture it on the custom runner's side, passing it to Nose without a problem.

它忽略了-s,让我在自定义运行器的一侧捕获它,毫无问题地传递给鼻子。

#2


32  

Yeah, this issue is cause by NoseTestSuiteRunner. Add -- -s is a tricky but not the best solutions. Try to add follow lines in the settings.py:

是的,这个问题是由NoseTestSuiteRunner引起的。-- s是一个棘手的问题,但不是最好的解决方案。尝试在set .py中添加跟随行:

NOSE_ARGS = ['--nocapture',
             '--nologcapture',]

Which solved my problems.

这解决了我的问题。

#3


4  

You probably have some intermediate test runner, such as Nose, intercepting and storing stdout. Try either running the Django tests directly, or write to stderr instead.

您可能有一些中间测试运行器,比如Nose、拦截和存储stdout。尝试直接运行Django测试,或者将其写入stderr。

#4


0  

Using current versions of all the relevant packages (Django==1.11.2, django-nose==1.4.5 and nose==1.3.7) it is sufficient to add the --nocapture flag when running your tests. Thus a simple

使用所有相关包的当前版本(Django==1.11.2, Django -nose==1.4.5和nose==1.3.7),在运行测试时添加nocapture标志就足够了。这样一个简单的

./manage.py test --nocapture

will suffice.

就足够了。

Granted of course that you have

当然你有

TEST_RUNNER = "django_nose.NoseTestSuiteRunner"

in your settings.py

在你settings.py

#1


32  

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:

检查TEST_RUNNER设置。py,它使用了一个项目专用的跑步者来呼叫鼻子。Nose有-s选项可以阻止它捕获stdout,但是如果我运行:

./manage.py test -s

/管理。py - s测试

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:

管理。py首先捕获它并抛出一个“没有这样的选项”错误。帮助管理。py没有提到这个,但是我发现如果我跑:

./manage.py test -- -s

/管理。py测试——- s

it ignores the -s and lets me capture it on the custom runner's side, passing it to Nose without a problem.

它忽略了-s,让我在自定义运行器的一侧捕获它,毫无问题地传递给鼻子。

#2


32  

Yeah, this issue is cause by NoseTestSuiteRunner. Add -- -s is a tricky but not the best solutions. Try to add follow lines in the settings.py:

是的,这个问题是由NoseTestSuiteRunner引起的。-- s是一个棘手的问题,但不是最好的解决方案。尝试在set .py中添加跟随行:

NOSE_ARGS = ['--nocapture',
             '--nologcapture',]

Which solved my problems.

这解决了我的问题。

#3


4  

You probably have some intermediate test runner, such as Nose, intercepting and storing stdout. Try either running the Django tests directly, or write to stderr instead.

您可能有一些中间测试运行器,比如Nose、拦截和存储stdout。尝试直接运行Django测试,或者将其写入stderr。

#4


0  

Using current versions of all the relevant packages (Django==1.11.2, django-nose==1.4.5 and nose==1.3.7) it is sufficient to add the --nocapture flag when running your tests. Thus a simple

使用所有相关包的当前版本(Django==1.11.2, Django -nose==1.4.5和nose==1.3.7),在运行测试时添加nocapture标志就足够了。这样一个简单的

./manage.py test --nocapture

will suffice.

就足够了。

Granted of course that you have

当然你有

TEST_RUNNER = "django_nose.NoseTestSuiteRunner"

in your settings.py

在你settings.py