no output in console for unittests in pycharm 2017

后端 未结 4 1896
温柔的废话
温柔的废话 2021-02-04 05:50

I have created unitests using import unittest. When I want to run a specific test and I put a breakpoint then go to the console and try to eval expressions there\'s no r

相关标签:
4条回答
  • 2021-02-04 06:04

    I had the issue running pytests for django in the Pycharm debugger. Adding -s as a parameter did the trick for me. As seen in the Pycharm bugreport: PY-22505 from Zach's answer.

    0 讨论(0)
  • 2021-02-04 06:18

    Looks like the official fix for this bug, PY-22505, is to add the new JB_DISABLE_BUFFERING environment variable to your unit test configurations (no value required, per screenshot), but only for 2017.1.3 or greater.

    This screenshot shows adding the env var for the Defaults config, so all new configs will inherit it. You could also add this individually to already-saved Run/Debug configurations:

    With that env var in place, I can now:

    1. add a breakpoint
    2. right-click any test or class and choose the 'Debug Unittests for ...' menu option
    3. hit breakpoint, go to debug console
    4. inspect my runtime and get the printouts (note 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)
  • 2021-02-04 06:19

    Pycharm unit test interactive debug command line doesn't work

    use pytest

    (Run > Edit Configurations > Defaults > Python tests > py.test > add -s to the options field------>(Additional Arguments).)

    settings default run tests by pytest:

    (Preferences > Tools > Python Intergrated Tools > default test runner)

    0 讨论(0)
  • 2021-02-04 06:27

    Could this be because you use pycharm 2017.1 combined with a python environment that has teamcity-messages in it? That combi crashes, see https://youtrack.jetbrains.com/issue/PY-23926

    Upvote that ticket if that's the case please (making an account took me 1 min).

    0 讨论(0)
提交回复
热议问题