Repository navigation
Print statements not showing in debug console during test debugging #899
Description
Behaviour
Expected vs. Actual
When debugging a Python file, if I run a print command from the debug console (like print("hello")), I see the result of the command in two places- both in the debug console and in the terminal the debugger is connected to. If I simply enter a string in the debug console it also returns, but it is a pain to use if there are newlines in it. A screenshot of what I see when I use the file debugger is below.
Within the last week or two, I have noticed that if I debug a Python test and I run a print command, the result does not appear in the console. Furthermore, when debugging tests, it does not connect to the same terminal that the Python file debugger does so I can't check the printed result there either. If I simply enter a string in the debug console it does return, but it is a pain to use if there are newlines in it. A screenshot of what I see when I use the test debugger is below.

I would expect that running a print command in the debug console while debugging a test would show the printed value in the debug console just as it does when debugging a file.
Steps to reproduce:
- Set a breakpoint in a Python test.
- Debug the test, either from the file or the testing pane
- When the code hits the breakpoint, enter
print("hello")in the debug console - Nothing is printed, and since the test debugger is not connected to the same terminal that the file debugger connects to, the output does not appear there either.
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.9.2
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Poetry
- Value of the
python.languageServersetting: Pylance
User Settings
defaultLS: {"defaultLSType":"Pylance"}
downloadLanguageServer: true
envFile: "<placeholder>"
venvPath: "<placeholder>"
venvFolders: "<placeholder>"
condaPath: "<placeholder>"
pipenvPath: "<placeholder>"
poetryPath: "<placeholder>"
languageServer: "Pylance"
linting
• enabled: true
• cwd: "<placeholder>"
• Flake8Args: "<placeholder>"
• flake8Enabled: true
• flake8Path: "<placeholder>"
• lintOnSave: true
• banditArgs: "<placeholder>"
• banditEnabled: false
• banditPath: "<placeholder>"
• mypyArgs: "<placeholder>"
• mypyEnabled: false
• mypyPath: "<placeholder>"
• pycodestyleArgs: "<placeholder>"
• pycodestyleEnabled: false
• pycodestylePath: "<placeholder>"
• prospectorArgs: "<placeholder>"
• prospectorEnabled: false
• prospectorPath: "<placeholder>"
• pydocstyleArgs: "<placeholder>"
• pydocstyleEnabled: false
• pydocstylePath: "<placeholder>"
• pylamaArgs: "<placeholder>"
• pylamaEnabled: false
• pylamaPath: "<placeholder>"
• pylintArgs: "<placeholder>"
• pylintPath: "<placeholder>"
sortImports
• args: "<placeholder>"
• path: "<placeholder>"
formatting
• autopep8Args: "<placeholder>"
• autopep8Path: "<placeholder>"
• provider: "black"
• blackArgs: "<placeholder>"
• blackPath: "<placeholder>"
• yapfArgs: "<placeholder>"
• yapfPath: "<placeholder>"
testing
• cwd: "<placeholder>"
• debugPort: 3000
• nosetestArgs: "<placeholder>"
• nosetestsEnabled: false
• nosetestPath: "<placeholder>"
• promptToConfigure: true
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• pytestPath: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: false
• autoTestDiscoverOnSaveEnabled: false
terminal
• activateEnvironment: true
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"
experiments
• enabled: true
• optInto: []
• optOutFrom: []
tensorBoard
• logDirectory: "<placeholder>"
Activity
fabioz commentedon Apr 11, 2022
This happens because
pytestcaptures the output.If you don't want that behavior you can pass
--capture=noin the pytest command line arguments to disable it.-- this changed from the last version because previously we'd always capture and print the output, but on the regular case what'd happen is that the output would appear printed twice. Now we no longer do that, but this has the downside that if a tool (such as pytest) captures it nothing will be printed.
I guess we could potentially have some setting to always replay messages, but I'm not sure it's much better than disabling the pytest capture (in practice when debugging I always disable pytest capture because you're usually debugging a single test anyways and the capture in this case is just annoying).
pabloazurduy commentedon Jul 7, 2022
+1 to this issue, some workarounds that I found
adriangb commentedon Apr 7, 2023
Fabio Zadrozny (@fabioz) where does that need to be set? I've tried setting it via
"python.testing.pytestArgs"insettings.jsonbut that seems to apply to things run via theRuntab not theTeststab. I tried setting it in the Pytest configuration (addopts = '--no-capture'in the[tool.pytest.ini_options]section ofpyproject.toml) and that doesn't work either.liuyang2356 commentedon Jun 22, 2024
I tried setting it in my
pytest.iniand it works.