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']
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).
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:
inspect my runtime and get the printouts (note
captureStandardOutput='true'
):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)