-
Notifications
You must be signed in to change notification settings - Fork 68
Debugging pytests Using Subprocesses Fails #1548
Comments
Or do you guys think this would better be reported in microsoft/ptvsd? |
@schanzel Try these instructions and see if they help. https://github.com/microsoft/ptvsd/blob/master/TROUBLESHOOTING.md#1-multiprocessing-on-linuxmac |
Note that this is using I suspect this might have something to do with |
Adding import multiprocessing
multiprocessing.set_start_method('spawn', True) did not help out, got the same result. |
If you don't use the test explorer and just a debug run with the code below, do you still have the error?
As a note, on how this happens in mac: it actually does a I've tested things here and I can reproduce it using the test runner (with a regular test run and with a debug test run) and I can't reproduce it without the test running (in a regular run), so, it seems like the issue isn't really in the debugger but in the test runner. @schanzel can you confirm if that's also the case for you? |
Actually, I'm sorry, I can't reproduce it with a regular test, just with a debug test (but it needs both the debug enabled and the test run). Also, if |
@fabioz yes, this is exactly the combination in which the issue ocures. |
@karthiknadig any news here yet? |
@fabioz Any ideas on what needs to be done here? |
@karthiknadig not really... this needs further investigation and I think it will take a while to properly debug why this may be happening -- I think it's more related to p.s.: I've actually seen some strange interactions when |
FWIW, I took out |
@awichmann-mintel yes that solves the issue, but interesting enough that the test results differ when debugging vs. a non-debug run. Besides, I found another case in which debugging test runs leads to different results, even when the apt-get install sysstat Please consider the following example below. def test_sadf_output():
result = subprocess.run(
["sadf", "-c", "/tmp/test"],
)
assert result.returncode == 0 Do you think this might be related? |
I think that yes, it's possible that it's related... One possibility is that the environment is not correct. Can you run the following and attach the output in the case that it works and in the case that it doesn't work to see if it matches?
Another thing to check: if you pass the full path to |
Sure, here you go! I don't see any significant difference here, do you? Failure (Debug) Case
"Success" (non-debug) Case
|
Can you also provide it in the case that it does work? |
Also, if you run that without the test running (in a |
Yes, running that with a debugger in a
I attached the output to my previous comment. |
Well, there are many differences actually... (i.e.: It may be interesting to create a copy of the env where it works and use it in the case where it doesn't work to see if it makes a difference. You can just do a print(repr(environ)) in the case that it works and then pass that as a parameter in the case where it doesn't work. |
Tried that but got the exact same result (return code env = {
'HTTP_PROXY': 'http://host.docker.internal:3128',
'LANG': 'en_US.UTF-8',
'HOSTNAME': 'b7118041f6b2',
'AMD_ENTRYPOINT': 'vs/server/remoteExtensionHostProcess',
'APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL': 'true',
'PWD': '/workspaces/remote-container-test',
'HOME': '/root',
'TERM_PROGRAM': 'vscode',
'TERM_PROGRAM_VERSION': '1.36.1',
[...]
'PYTHONIOENCODING': 'UTF-8',
'PYTHONUNBUFFERED': '1',
'LC_CTYPE': 'C.UTF-8'
}
def test_sadf_output():
import os
import subprocess
result = subprocess.run(["sadf", "-c", "/tmp/test"], env=env)
assert result.returncode == 0 |
Can you try one more thing there? In To find where that module is in your case you should be able to do:
|
That seems to actually help! With these changes I get the correct result using a debug test run. |
I'll have to investigate the test runner... it's possible that it also has some patching that's conflicting with the debugger patching (as that same code works when the test runner is not being used). |
As a side note: The |
I found the culprit... the problem is that The difference from the test running is that the test runner always enables I'll provide a fix shortly. |
@fabioz Hey thats awesome, thanks for the fast help! |
Environment data
Expected behaviour
Test results when running with debugger are identical to the results from a run without debugger.
Actual behaviour
Tests fail because subprocess can not be successfully executed when running tests with the debugger attached.
Steps to reproduce:
subprocess
es and it'sshell
argument set toTrue
returncode
is2
(alsostdout
andstderr
are empty)Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging
)The text was updated successfully, but these errors were encountered: