控制台中没有用于pycharm 2017中单元测试的输出

控制台中没有用于pycharm 2017中单元测试的输出,pycharm,teamcity,Pycharm,Teamcity,我已经使用importunittest创建了单元测试。当我想运行一个特定的测试并设置一个断点,然后转到控制台并尝试评估表达式时,没有返回值,就好像标准输出不再是控制台屏幕一样。 我从未安装过teamcity,但奇怪的是,我在运行unittest时确实收到消息。很奇怪。我认为可能是captureStandardOutput='true'(在下面最后一行强调)导致了问题,但我甚至找不到在哪里更改参数来测试它 C:\Users\selas\AppData\Local\Continuum\Anacond

我已经使用importunittest创建了单元测试。当我想运行一个特定的测试并设置一个断点,然后转到控制台并尝试评估表达式时,没有返回值,就好像标准输出不再是控制台屏幕一样。

我从未安装过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']
C:\Users\selas\AppData\Local\Continuum\Anaconda3\python.exe“C:\Program Files(x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pydev\pydev.py”--多进程--qt支持--客户端127.0.0.1--端口59641--文件“C:\Program Files(x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\PyCharm\\ jb\u unittest\u runner.py”--目标测试.测试\模型.图形DBTesting.测试\打印图形边界
pydev调试器:进程8932正在连接
已连接到pydev调试器(构建171.3780.115)
teamcity[输入的矩阵时间戳='…']
使用参数python-m unittest tests.test_model.FigurationDBTesting.test_printFigurationPerBoundary启动unittests
teamcity[testSuiteStarted timestamp='…'locationHint='1]python://tests'name='tests'nodeId='1'parentNodeId='0']
teamcity[testSuiteStarted timestamp='…'locationHint='1]python://tests.test_model'name='test_model'nodeId='2'parentNodeId='1']
teamcity[testSuiteStarted timestamp='…'locationHint='1]python://tests.test_model.FigurationDBTesting'name='FigurationDBTesting'nodeId='3'parentNodeId='2']
teamcity[testStarted timestamp='…'>!>captureStandardOutput='true'

使用pytest

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

设置默认按pytest运行测试:


(首选项>工具>Python集成工具>默认测试运行程序)

这可能是因为您将pycharm 2017.1与包含teamcity消息的Python环境结合使用造成的吗?combi崩溃,请参阅


如果是这样的话,请向上投票(我花了1分钟的时间来创建一个帐户)。

看起来这个错误的官方解决方案是将新的
JB\u DISABLE\u BUFFERING
环境变量添加到您的单元测试配置中(每个屏幕截图不需要值),但仅适用于2017.1.3或更高版本

此屏幕截图显示如何为默认值配置添加环境变量,以便所有新配置将继承它。您也可以将其单独添加到已保存的运行/调试配置中:

有了环境变量,我现在可以:

  • 添加断点
  • 右键单击任何测试或类,然后选择“调试…的Unittests”菜单选项
  • 点击断点,转到调试控制台
  • 检查我的运行时并获取打印输出(注意
    captureStandardOutput='true'
    ):

    。。。
    ##teamcity[testStarted timestamp='…'captureStandardOutput='true'locationHint='python://test_distance.Foo.testMatchRatio_050'name='testMatchRatio_050'nodeId='3'parentNodeId='2']
    导入系统;打印(“%s%”(sys.version,sys.platform)上的Python%s)
    Python 2.7.13(v2.7.13:a06454b1afa1,2016年12月17日,12:39:47)
    [GCC 4.2.1(苹果公司建造5666)(dot 3)]关于达尔文
    >>>打印(自我)
    testMatchRatio_050(test_distance.Foo)
    

  • 我在Pycharm调试器中运行django的pytests时遇到了问题。添加
    -s
    作为参数对我起了作用。正如Pycharm bugreport中所示:来自Zach的答案。

    您可以尝试编辑
    helpers/Pycharm/teamcity/unittestpy.py
    (在我Mac上的Pycharm.app包中,不确定它在Windows的哪个位置)。我将其更改为
    captureStandardOutput='false'
    ,调试器以我修改的值启动,但结果相同:(@KarelMacek你有哪个版本的PyCharm?事实上,我没有将该变量添加到现有的测试中。这对我来说是可行的:
    PyCharm 2017.2.3
    构建#PY-172.3968.37,于2017年9月1日构建
    JRE:1.8.0152-release-915-b11 x86_64
    JVMS X 10.12.6有没有办法全局设置此设置?(在2017.2.4中对我有效)@ZacharyYoung运行配置中的默认值似乎是按项目设置的默认值。因此我必须在所有项目中分别设置此设置。tbh这没什么大不了的,但我正在寻找一个为多个项目全局设置此设置的位置。
    ...
    ##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)