2017-04-11 109 views
10

我使用import unittest创建了unitests。当我想运行一个特定的测试,然后放置一个断点,然后转到控制台并尝试评估表达式没有返回值,就好像stdout不再是控制台屏幕一样。pycharm中单元测试控制台无输出2017

我从来没有安装teamcity,但奇怪的是我运行unittest时会收到消息。很奇怪。我认为这可能是captureStandardOutput ='true'(在最后一行强调,下面)是问题的原因,但我什至不能找到在哪里更改参数来测试它。

C:\Users\selas\AppData\Local\Continuum\Anaconda3\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 59641 --file "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pycharm\_jb_unittest_runner.py" --target tests.test_model.FigurationDBTesting.test_printFigurationPerBoundary 
pydev debugger: process 8932 is connecting 
Connected to pydev debugger (build 171.3780.115) 

teamcity[enteredTheMatrix timestamp='...'] 
Launching unittests with arguments python -m unittest tests.test_model.FigurationDBTesting.test_printFigurationPerBoundary 
teamcity[testSuiteStarted timestamp='...' locationHint='python://tests' name='tests' nodeId='1' parentNodeId='0'] 
teamcity[testSuiteStarted timestamp='...' locationHint='python://tests.test_model' name='test_model' nodeId='2' parentNodeId='1'] 
teamcity[testSuiteStarted timestamp='...' locationHint='python://tests.test_model.FigurationDBTesting' name='FigurationDBTesting' nodeId='3' parentNodeId='2'] 

teamcity[testStarted timestamp='...' >!> captureStandardOutput='true' <!< locationHint='python://tests.test_model.FigurationDBTesting.test_printFigurationPerBoundary' name='test_printFigurationPerBoundary' nodeId='4' parentNodeId='3'] 
+0

你可以尝试编辑'''助手/ pycharm/TeamCity的/ unittestpy.py'''(在PyCharm.app包在我的Mac上,不确定它在Windows中的位置)。我把它改成'''captureStandardOutput ='false''''并且调试器以我的修改值开始,但是它的结果是一样的: –

回答

-1

Pycharm unit test interactive debug command line doesn't work

使用pytest

(运行>编辑配置>默认值>的Python测试> py.test>添加-s到选项字段------>(附加参数。))

设置默认运行测试通过pytest:

(首选项>工具> Python的Intergrated工具>默认测试运行器)

+0

它对我来说不适用于Pycharm 2017.1.2 ... –

9

看起来像这个bug,PY-22505官方修复,是新JB_DISABLE_BUFFERING环境变量添加到您的单元测试配置(不需要值,每截图),但仅限于2017年1月3日或以上

此屏幕截图显示添加env var的默认值配置,所以所有新的配置将继承它。您还可以添加此单独已保存的运行/调试配置:

Setting env var for all future ad-hoc tests

随着地方的环境变量,我现在可以:

  1. 添加断点
  2. 右击任何测试或类别,并选择'调试单元测试...'菜单选项
  3. 命中断点,转到调试控制台
  4. 检查我的运行时间,并获得打印输出(注意captureStandardOutput='true'):

    ... 
    ##teamcity[testStarted timestamp='...' captureStandardOutput='true' locationHint='python</Users/zyoung/PycharmProjects/Foo/test/unit_tests>://test_distance.Foo.testMatchRatio_050' name='testMatchRatio_050' nodeId='3' parentNodeId='2'] 
    import sys; print('Python %s on %s' % (sys.version, sys.platform)) 
    Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin 
    
    >>> print(self) 
    testMatchRatio_050 (test_distance.Foo) 
    
+0

这只是做不工作 –

+0

@KarelMacek你有哪种版本的PyCharm? –

+0

它确实对我有用,使用PyCharm 2017.2.2 –