Pycharm单元测试交互式调试命令行不起作用 [英] Pycharm unit test interactive debug command line doesn't work
问题描述
>> ;打印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屋!