From f0e35dfed4d67d47f17a36507b8dc25a51a73a8b Mon Sep 17 00:00:00 2001 From: Pavel Karateev Date: Fri, 24 Oct 2025 13:59:24 +0200 Subject: [PATCH] [python] PY-84514 fix debugger import in isolated mode there is already code to tweak `sys.path` to workaround the isolated mode, we just need to import all debugger stuff AFTER it (cherry picked from commit acc72ae1a88e4533243a43c30bda4ab3b62c3ec9) IJ-MR-179907 GitOrigin-RevId: af64cb82c3a79fbd133c303ddb0975f7b70a7f26 --- python/helpers/pydev/pydevd.py | 3 +-- python/helpers/pydev/tests/test_pydevd.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 python/helpers/pydev/tests/test_pydevd.py diff --git a/python/helpers/pydev/pydevd.py b/python/helpers/pydev/pydevd.py index bf969108c971..122602256db3 100644 --- a/python/helpers/pydev/pydevd.py +++ b/python/helpers/pydev/pydevd.py @@ -8,14 +8,13 @@ import sys from contextlib import contextmanager import weakref -from _pydevd_bundle.pydevd_daemon_thread import run_as_pydevd_daemon_thread - # allow the debugger to work in isolated mode Python here = os.path.dirname(os.path.abspath(__file__)) if here not in sys.path: sys.path.insert(0, here) from _pydevd_bundle.pydevd_collect_try_except_info import collect_return_info +from _pydevd_bundle.pydevd_daemon_thread import run_as_pydevd_daemon_thread if sys.version_info[:2] < (2, 6): raise RuntimeError('The PyDev.Debugger requires Python 2.6 onwards to be run. If you need to use an older Python version, use an older version of the debugger.') diff --git a/python/helpers/pydev/tests/test_pydevd.py b/python/helpers/pydev/tests/test_pydevd.py new file mode 100644 index 000000000000..b620993ea691 --- /dev/null +++ b/python/helpers/pydev/tests/test_pydevd.py @@ -0,0 +1,19 @@ +import pytest + +from _pydevd_bundle.pydevd_constants import IS_PY3K + +if IS_PY3K: + import sys + import subprocess + from pathlib import Path + + +@pytest.mark.python3(reason="`-I` is introduced in 3.4") +def test_isolated_mode(): + script = Path("pydevd.py") + result = subprocess.run( + [sys.executable, "-I", str(script), "--help"], + cwd=Path.cwd(), + ) + + assert result.returncode == 0