Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print() doesn't work in debug console while debugging pytests #19949

Closed
zljubisic opened this issue Oct 5, 2022 · 21 comments
Closed

print() doesn't work in debug console while debugging pytests #19949

zljubisic opened this issue Oct 5, 2022 · 21 comments
Assignees
Labels
area-debugging area-testing bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team

Comments

@zljubisic
Copy link

Type: Bug

If I set a breakpoint in pytest test, when I am on the breakpoint, if I enter debug console and execute prints, nothing is showed up.
Is that a bug or feature?

Extension version: 2022.14.0
VS Code version: Code 1.71.2 (74b1f979648cc44d385a2286793c226e611f59e7, 2022-09-14T21:03:37.738Z)
OS version: Windows_NT x64 10.0.19042
Modes:
Sandboxed: No
Remote OS version: Linux x64 3.10.0-1127.el7.x86_64

image

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Oct 5, 2022
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-debugging labels Oct 5, 2022
@fabioz
Copy link

fabioz commented Oct 6, 2022

This is a duplicate of: #19322

@zljubisic
Copy link
Author

zljubisic commented Oct 7, 2022

I am not sure that this is the same issue because I have this in settings.json, so it is not matter of defaults.

{
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
    "python.testing.pytestArgs": [
        "--no-cov", "-s"
    ]
}

@fabioz
Copy link

fabioz commented Oct 7, 2022

{
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--no-cov", "-s"
]
}

Can you type in sys.argv in the Debug Console to check what are the actual args being received in your case? (i.e.: setting that works for me...).

@zljubisic
Copy link
Author

For settings.json like:

{
    "python.testing.pytestArgs": [
        "tests",
        "--no-cov",
        "--capture=no"
        // "-s"
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
    "testing.defaultGutterClickAction": "debug"
}

I get:

00:
'/home/vagrant/.vscode-server/extensions/ms-python.python-2022.14.0/pythonFiles/testlauncher.py'
01:
'/home/vagrant/ticket...
02:
'pytest'
03:
'--rootdir'
04:
'/home/vagrant/...'
05:
'--override-ini'
06:
'junit_family=xunit1'
07:
'--junit-xml=/tmp/tmp-2214147HpdLUh2ky1.xml'
08:
'--no-cov'
09:
'--capture=no'
10:
'./tests/test_mytest.py::name of test...]'
len():
11

At the moment I can print, but from time to time print(12) just make an empty line. Do you see different vertical spaces? They are when print fails. Usually I don't have anything as output.

image

@fabioz
Copy link

fabioz commented Oct 7, 2022

The fact that it doesn't write sometimes due to the clipping is already reported at:

microsoft/vscode#162965

(so, this can be closed as a duplicate).

@zljubisic
Copy link
Author

I don't know is it the same issue.
In microsoft/vscode#162965 problem is dataframe related, here the problem is with general print.
I hope that in the future I will be able to use rich print (from rich import print) to print complex object like nested dictionaries in pretty format.

@eleanorjboyd
Copy link
Member

Hello! This is a duplicate of #19322 which just got resolved in this PR by @harupy.

@zljubisic
Copy link
Author

Usually, end user (UAT) should confirm that problem is solved.

@eleanorjboyd
Copy link
Member

@zljubisic, yes this is true - can someone verify?

@eleanorjboyd eleanorjboyd reopened this Oct 12, 2022
@zljubisic
Copy link
Author

It kind of works if you don't count occasional empty line. Please look at the space between second print and word "first".

image

The same goes with dictionary as well. You can see empty line that shows up occasionally.

image

I try to use rich print as well (from rich import print), and again, empty line (or two) show up in few 5-6 successive print executions.

@zljubisic
Copy link
Author

I have just experienced problems with print in debug console again, so this problem is not solved:

image

@fabioz
Copy link

fabioz commented Oct 20, 2022

@zljubisic can you provide the debugger logs for that case?

See: https://github.com/microsoft/debugpy/wiki/Enable-debugger-logs for details on how to collect the logs.

@zljubisic
Copy link
Author

This has happened on my business computer.
I am not sure what you are collecting and whether I am allowed to provide the logs to you. 🤔

@fabioz
Copy link

fabioz commented Oct 20, 2022

You can verify the log messages and anonymize accordingly before sending the logs.

@zljubisic
Copy link
Author

Do you have some anonymizing function that can do that, or I have to pass over the files visually?

@zljubisic
Copy link
Author

Do I have to put "purpose": ["debug-test", "debug-in-terminal"], in launch.json?

{
    "name": "Python: Current File",
    "type": "python",
    "request": "launch",
    "program": "${file}",
    "console": "integratedTerminal",
    "logToFile": true,
}

@fabioz
Copy link

fabioz commented Oct 20, 2022

Do you have some anonymizing function that can do that, or I have to pass over the files visually?

You need to pass them yourself and determine what's important for you to remain anonymous.

Do I have to put "purpose": ["debug-test", "debug-in-terminal"], in launch.json?

If you launch it through the testing tab or dropdown in editor yes.

@zljubisic
Copy link
Author

@fabioz in case of vscode executed on windows 10 but connected to centos 7 in hyperv, where I should expect logs to show up?
In linux or windows?

@zljubisic
Copy link
Author

Just to confirm that problem with print() is still present.

@fabioz
Copy link

fabioz commented Oct 28, 2022

@fabioz in case of vscode executed on windows 10 but connected to centos 7 in hyperv, where I should expect logs to show up?
In linux or windows?

It should be in Linux. I suggest you go with the environment variable in this case and point the environment variable to the place you'd like the logs to be on Linux.

p.s.: you have to do the log anonymizing manually and decide what you're comfortable sharing or not (as it's a sample case with sample code, I don't expect you to have to anonymize much...).

@eleanorjboyd
Copy link
Member

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging area-testing bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants