Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

no output in console for unittests in pycharm 2017

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 return value as if the stdout is no longer the console screen.

I have never installed teamcity but strangely I do get messages when running the unittest. VERY STRANGE. I thought that maybe the captureStandardOutput='true' (emphasized on last line, below) is the cause of the problem but I can't even find where to change the param to test it.

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']
like image 910
bach Avatar asked Apr 11 '17 14:04

bach


People also ask

How do I get output in Pycharm?

Open settings by pressing ⌘ , , navigate to Tools | Database | Query Execution | Output and Results.

How are test successes identified?

If the test fails or errors in the test function itself (rather than in one of the test fixture methods) then it will be considered a success.


1 Answers

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:

Setting env var for all future ad-hoc tests

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)
    
like image 53
Zach Young Avatar answered Oct 14 '22 09:10

Zach Young