PY-78884 Linux in Docker for PyCharm config PyEnvTestsDebugger

First iteration. Minor errors fixed.


Merge-request: IJ-MR-154104
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: c4410fdf09edef7c0974ecb6bb15dbd465defbca
This commit is contained in:
Egor Eliseev
2025-01-31 17:44:33 +00:00
committed by intellij-monorepo-bot
parent c46cf087d1
commit 52eaf0d631
8 changed files with 77 additions and 47 deletions

View File

@@ -9,7 +9,7 @@ def calculate_sum(a, b):
def greet(name):
# Use a breakpoint here to debug the call
print(f"Hello, {name}!")
print("Hello, {name}!".format(name=name))
if __name__ == "__main__":
@@ -20,7 +20,7 @@ if __name__ == "__main__":
num1 = counter
num2 = counter + 1
sum_result = calculate_sum(num1, num2) # Step into this function during debugging
print(f"The sum of {num1} and {num2} is: {sum_result}")
print("The sum of {num1} and {num2} is: {sum_result}".format(num1=num1, num2=num2, sum_result=sum_result))
greet("Debugger") # Also step into this function if needed
counter += 1
# Add a sleep to slow down the loop and make debugging easier

View File

@@ -2,6 +2,6 @@ from __future__ import print_function
import os
import subprocess
ret = subprocess.call([os.path.abspath('test_executable_script_debug_helper.py')], stderr=subprocess.PIPE)
ret = subprocess.call([os.path.abspath('test_executable_script_debug_helper.py')], shell=True, stderr=subprocess.PIPE)
print("Subprocess exited with return code: %d" % ret)

View File

@@ -1,6 +1,6 @@
import numpy as np
np_arr = np.array(range(10000))
# import numpy as np
#
# np_arr = np.array(range(10000))
lst = ['a'] * 10000
print()

View File

@@ -7,5 +7,5 @@ def f(x):
if __name__ == '__main__':
with multiprocessing.Pool() as p:
print(p.map(f, [1, 2, 3]))
p = multiprocessing.Pool()
print(p.map(f, [1, 2, 3]))

View File

@@ -6,6 +6,6 @@ def run(name):
print(name)
if __name__ == '__main__':
multiprocessing.Process(target=run, args=("subprocess",)).start()
while True:
time.sleep(0.1)
p = multiprocessing.Process(target=run, args=("subprocess",))
p.start()
p.join()

View File

@@ -1,18 +1,15 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.env.debug;
import com.google.common.collect.ImmutableSet;
import com.intellij.idea.TestFor;
import com.intellij.openapi.util.SystemInfo;
import com.jetbrains.env.EnvTestTagsRequired;
import com.jetbrains.env.PyEnvTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assume;
import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -81,6 +78,7 @@ public class PythonDebuggerMultiprocessingTest extends PyEnvTestCase {
@Override
public void testing() throws Exception {
waitForOutput("Done");
waitForTerminate();
assertFalse(output().contains("KeyboardInterrupt"));
}
});
@@ -117,8 +115,8 @@ public class PythonDebuggerMultiprocessingTest extends PyEnvTestCase {
public void testing() throws Exception {
waitForPause();
resume();
waitForOutput("The subprocess finished with the return code 0.");
waitForTerminate();
outputContains("The subprocess finished with the return code 0.");
}
});
}
@@ -148,7 +146,6 @@ public class PythonDebuggerMultiprocessingTest extends PyEnvTestCase {
@Override
public void before() {
toggleBreakpoint(getFilePath("test_multiprocess_process.py"), 5);
setWaitForTermination(false);
}
@Override
@@ -156,6 +153,7 @@ public class PythonDebuggerMultiprocessingTest extends PyEnvTestCase {
waitForPause();
eval("name").hasValue("'subprocess'");
resume();
waitForTerminate();
}
});
}
@@ -235,6 +233,7 @@ public class PythonDebuggerMultiprocessingTest extends PyEnvTestCase {
@Test
@TestFor(issues = "PY-37366")
@EnvTestTagsRequired(tags = "python3")
public void testMultiprocessManagerFork() {
runPythonTest(new PyDebuggerMultiprocessTask("/debug", "test_multiprocess_manager_fork.py") {
@Override
@@ -264,7 +263,7 @@ public class PythonDebuggerMultiprocessingTest extends PyEnvTestCase {
@Override
public void testing() throws Exception {
var expectedValues = new HashSet<String>();
for (int i = 0; i < 3; i++) {
for (int i = 1; i < 4; i++) {
expectedValues.add(Integer.toString(i));
}

View File

@@ -6,6 +6,7 @@ import com.intellij.openapi.util.SystemInfo;
import com.intellij.testFramework.UsefulTestCase;
import com.jetbrains.env.PyEnvTestCase;
import com.jetbrains.python.debugger.PyDebuggerOptionsProvider;
import com.jetbrains.python.psi.LanguageLevel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assume;
@@ -26,6 +27,11 @@ public class PythonDebuggerQtTest extends PyEnvTestCase {
public Set<String> getTags() {
return ImmutableSet.of("qt");
}
@Override
public boolean isLanguageLevelSupported(@NotNull final LanguageLevel level) {
return level.compareTo(LanguageLevel.PYTHON38) != 0;
}
}
@Test

View File

@@ -16,6 +16,7 @@ import com.jetbrains.python.console.pydev.PydevCompletionVariant;
import com.jetbrains.python.debugger.*;
import com.jetbrains.python.debugger.pydev.ProcessDebugger;
import com.jetbrains.python.debugger.settings.PyDebuggerSettings;
import com.jetbrains.python.psi.LanguageLevel;
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -65,7 +66,13 @@ public class PythonDebuggerTest extends PyEnvTestCase {
@Test
public void testBreakpointStopAndEval() {
runPythonTest(new BreakpointStopAndEvalTask("test1.py"));
runPythonTest(new BreakpointStopAndEvalTask("test1.py") {
@Override
public void before() {
toggleBreakpoint(getFilePath(getScriptName()), 6);
setWaitForTermination(false);
}
});
}
@Test
@@ -151,6 +158,10 @@ public class PythonDebuggerTest extends PyEnvTestCase {
waitForOutput("command was GO!");
}
@Override
public boolean isLanguageLevelSupported(@NotNull final LanguageLevel level) {
return level.compareTo(LanguageLevel.PYTHON27) > 0;
}
});
}
@@ -498,6 +509,7 @@ public class PythonDebuggerTest extends PyEnvTestCase {
waitForPause();
eval(PyDebugValue.RETURN_VALUES_PREFIX + "['foo']").hasValue("33");
resume();
waitForTerminate();
}
@NotNull
@@ -581,8 +593,10 @@ public class PythonDebuggerTest extends PyEnvTestCase {
public void testing() throws Exception {
waitForPause();
eval("m").hasValue("42");
assertEquals("Thread1", getRunningThread());
resume();
var runningThread = myDebugProcess.getThreads().stream().filter(thread -> "Thread1".equals(thread.getName())).findFirst();
assertNotNull(runningThread);
setProcessCanTerminate(true);
disposeDebugProcess();
}
});
}
@@ -862,30 +876,6 @@ public class PythonDebuggerTest extends PyEnvTestCase {
});
}
@Test
public void testBuiltinBreakpoint() {
runPythonTest(new PyDebuggerTask("/debug", "test_builtin_break.py") {
@Override
public void before() {
toggleBreakpoint(getFilePath(getScriptName()), 2);
}
@Override
public void testing() throws Exception {
waitForPause();
resume();
waitForPause();
eval("a").hasValue("1");
resume();
}
@NotNull
@Override
public Set<String> getTags() {
return Collections.singleton("python3.7");
}
});
}
@Test
public void testTypeHandler() {
@@ -897,6 +887,11 @@ public class PythonDebuggerTest extends PyEnvTestCase {
toggleBreakpoint(getFilePath(getScriptName()), 11);
}
@Override
public boolean isLanguageLevelSupported(@NotNull final LanguageLevel level) {
return level.compareTo(LanguageLevel.PYTHON27) > 0;
}
@Override
public void testing() throws Exception {
waitForPause();
@@ -1270,6 +1265,11 @@ public class PythonDebuggerTest extends PyEnvTestCase {
setMultiprocessDebug(true);
}
@Override
public boolean isLanguageLevelSupported(@NotNull final LanguageLevel level) {
return level.compareTo(LanguageLevel.PYTHON27) > 0;
}
@Override
public void before() {
toggleBreakpoint(getFilePath(getScriptName()), 4);
@@ -1323,6 +1323,7 @@ public class PythonDebuggerTest extends PyEnvTestCase {
@Test
public void testCallingSettraceWarning() {
var warning = "PYDEV DEBUGGER WARNING:\nsys.settrace() should not be used when the debugger is being used.";
runPythonTest(new PyDebuggerTask("/debug", "test_calling_settrace_warning.py") {
@Override
public void before() {
@@ -1334,7 +1335,9 @@ public class PythonDebuggerTest extends PyEnvTestCase {
waitForPause();
resume();
waitForTerminate();
outputContains("PYDEV DEBUGGER WARNING:\nsys.settrace() should not be used when the debugger is being used.");
if (!stderr().contains(warning)) {
outputContains(warning);
}
}
@NotNull
@@ -1409,6 +1412,12 @@ public class PythonDebuggerTest extends PyEnvTestCase {
f()""");
waitForOutput("Foo, bar, baz");
resume();
waitForTerminate();
}
@Override
public boolean isLanguageLevelSupported(@NotNull final LanguageLevel level) {
return level.compareTo(LanguageLevel.PYTHON27) > 0;
}
});
}
@@ -1458,6 +1467,12 @@ public class PythonDebuggerTest extends PyEnvTestCase {
assertFalse("Output shouldn't contain debugger related stacktrace when debugger is stopped",
output().contains("pydevd.py\", line "));
}
@Override
public boolean isLanguageLevelSupported(@NotNull final LanguageLevel level) {
return level.compareTo(LanguageLevel.PYTHON38) != 0;
}
});
}
@@ -1600,6 +1615,11 @@ public class PythonDebuggerTest extends PyEnvTestCase {
waitForOutput("{\"u'Foo “Foo” Bar' (4706573888)\": '“Foo”'}");
waitForOutput("{b'\\xfc\\x00': b'\\x00\\x10'}");
}
@Override
public boolean isLanguageLevelSupported(@NotNull final LanguageLevel level) {
return level.compareTo(LanguageLevel.PYTHON27) > 0;
}
});
}
@@ -1623,9 +1643,15 @@ public class PythonDebuggerTest extends PyEnvTestCase {
waitForTerminate();
}
private void checkVariableValue(List<PyDebugValue> frameVariables, String expected, String name) throws PyDebuggerException {
private void checkVariableValue(List<PyDebugValue> frameVariables, String expected, String name)
throws PyDebuggerException, InterruptedException {
PyDebugValue value = findDebugValueByName(frameVariables, name);
loadVariable(value);
synchronized (this) {
while (value.getValue().isEmpty() || value.getValue().isBlank()) {
wait(1000);
}
}
assertEquals(expected, value.getValue());
}
});
@@ -1651,7 +1677,6 @@ public class PythonDebuggerTest extends PyEnvTestCase {
public void testing() throws Exception {
waitForPause();
testLength("lst");
testLength("np_arr");
resume();
}
});