Pycharm单元测试交互式调试命令行不起作用 [英] Pycharm unit test interactive debug command line doesn't work

查看:674
本文介绍了Pycharm单元测试交互式调试命令行不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试单元测试(通过pycharm测试运行器)可以打开交互式命令行,但是(与调试常规脚本不同),输入的命令不会产生任何输出。事实上,似乎stdout被捕获在某个地方,因为stderr的工作原理如下:

 >> ;打印a
>>>>导入sys
>>>> sys.stderr.write(moof)
moof
>>> sys.stdout.write(moof)
>>> sys.stderr.write(test)
test

这是预期的行为吗?我真的很喜欢交互式调试控制台,如果在调试单元测试时表现不错,那将会很棒。

解决方案

可能是因为你的测试运行器正在捕获stdout而不是stderr。



我使用 py.test 捕获stdout和stderr ,所以我看不出任何输出。如果我想看到输出,我必须将 -s 标志传递给我的py.test运行器,可以通过修改运行/调试配置并将此标志添加到选项字段。
(运行>编辑配置>默认值> Python测试> py.test>添加 -s 到options字段。)

 >>>打印'a'
a
>>>导入sys
>>>> sys.stderr.write('moof')
moof>>>> sys.stdout.write('moof')
moof>>>> sys.stderr.write('test')
test

注意:$ $ c> -s 标志可以同样用于鼻子测试


When debugging unit tests (through the pycharm test runner), one can turn on the interactive command line, but (unlike when debugging regular scripts) the commands entered don't produce any output. As a matter of fact, it appears that stdout is being captured somewhere, because stderr works as expected:

>>> print "a"
>>> import sys
>>> sys.stderr.write("moof")
moof
>>> sys.stdout.write("moof")
>>> sys.stderr.write("test")
test

Is this expected behavior? I really like the interactive debug console and it would be awesome if it behaved nice when debugging unit tests as well.

解决方案

This is likely because your test runner is capturing stdout but not stderr.

I use py.test which captures both stdout and stderr so I see no output at all. If I want to see output I have to pass the -s flag to my py.test runner which can be done by modifying the run/debug configuration and adding this flag to the options field. (Run > Edit Configurations > Defaults > Python tests > py.test > add -s to the options field.)

>>> print 'a'
a
>>> import sys
>>> sys.stderr.write('moof')
moof>>> sys.stdout.write('moof')
moof>>> sys.stderr.write('test')
test

Note: the -s flag can equally be used with nose tests

这篇关于Pycharm单元测试交互式调试命令行不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆