1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
From: Julian Gilbey <jdg@debian.org>
Date: Tue, 28 Oct 2025 12:16:57 -0700
Subject: Allow the tests to run outside of the build area
Forwarded: not-needed
Last-Update: 2024-06-30
---
tests_python/debugger_unittest.py | 10 ++++------
tests_python/test_run.py | 22 ++++++++++++++--------
tests_python/test_utilities.py | 4 ++--
3 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/tests_python/debugger_unittest.py b/tests_python/debugger_unittest.py
index 0c4dd3c..6b7901b 100644
--- a/tests_python/debugger_unittest.py
+++ b/tests_python/debugger_unittest.py
@@ -806,14 +806,12 @@ class AbstractWriterThread(threading.Thread):
return None
def get_pydevd_file(self):
- dirname = os.path.dirname(__file__)
- dirname = os.path.dirname(dirname)
- return os.path.abspath(os.path.join(dirname, "pydevd.py"))
+ import pydevd
+ return pydevd.__file__
def get_pydevconsole_file(self):
- dirname = os.path.dirname(__file__)
- dirname = os.path.dirname(dirname)
- return os.path.abspath(os.path.join(dirname, "pydevconsole.py"))
+ import pydevconsole
+ return pydevconsole.__file__
def get_line_index_with_content(self, line_content, filename=None):
"""
diff --git a/tests_python/test_run.py b/tests_python/test_run.py
index 785581e..ca11a60 100644
--- a/tests_python/test_run.py
+++ b/tests_python/test_run.py
@@ -32,14 +32,17 @@ def test_run(testdir_or_pytester):
foo_module = "tests_python.resources.launch.foo"
pydevd_dir = os.path.dirname(os.path.dirname(__file__))
- assert os.path.exists(os.path.join(pydevd_dir, "pydevd.py"))
+ if os.path.exists(os.path.join(pydevd_dir, "pydevd.py")):
+ append_path = "sys.path.append(%r)" % pydevd_dir
+ else:
+ append_path = ""
_run_and_check(
testdir_or_pytester,
testdir_or_pytester.makepyfile(
"""
import sys
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
import pydevd
py_db = pydevd.PyDB()
py_db.ready_to_run = True
@@ -54,7 +57,7 @@ py_db.run(%(foo_dir)r)
testdir_or_pytester.makepyfile(
"""
import sys
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
import pydevd
py_db = pydevd.PyDB()
py_db.run(%(foo_dir)r, set_trace=False)
@@ -72,7 +75,7 @@ py_db.run(%(foo_dir)r, set_trace=False)
testdir_or_pytester.makepyfile(
"""
import sys
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
sys.argv.append('--as-module')
import pydevd
py_db = pydevd.PyDB()
@@ -89,7 +92,7 @@ py_db.run(%(foo_module)r, is_module=True)
"""
import sys
sys.argv.append('--as-module')
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
import pydevd
py_db = pydevd.PyDB()
py_db.run(%(foo_module)r, is_module=True, set_trace=False)
@@ -104,7 +107,10 @@ def test_run_on_local_module_without_adding_to_pythonpath(testdir_or_pytester):
import os
pydevd_dir = os.path.dirname(os.path.dirname(__file__))
- assert os.path.exists(os.path.join(pydevd_dir, "pydevd.py"))
+ if os.path.exists(os.path.join(pydevd_dir, "pydevd.py")):
+ append_path = "sys.path.append(%r)" % pydevd_dir
+ else:
+ append_path = ""
foo_module = "local_foo"
with open(os.path.join(os.getcwd(), "local_foo.py"), "w") as stream:
@@ -116,7 +122,7 @@ def test_run_on_local_module_without_adding_to_pythonpath(testdir_or_pytester):
"""
import sys
import os
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
sys.argv.append('--as-module')
cwd = os.path.abspath(os.getcwd())
while cwd in sys.path:
@@ -138,7 +144,7 @@ py_db.run(%(foo_module)r, is_module=True)
import sys
import os
sys.argv.append('--as-module')
-sys.path.append(%(pydevd_dir)r)
+%(append_path)s
cwd = os.path.abspath(os.getcwd())
while cwd in sys.path:
sys.path.remove(cwd)
diff --git a/tests_python/test_utilities.py b/tests_python/test_utilities.py
index ac44a97..ef79729 100644
--- a/tests_python/test_utilities.py
+++ b/tests_python/test_utilities.py
@@ -290,7 +290,7 @@ def _build_launch_env():
cwd = os.path.abspath(os.path.dirname(__file__))
assert os.path.isdir(cwd)
- resources_dir = os.path.join(os.path.dirname(pydevd.__file__), "tests_python", "resources")
+ resources_dir = os.path.join(cwd, "resources")
assert os.path.isdir(resources_dir)
attach_to_process_dir = os.path.join(os.path.dirname(pydevd.__file__), "pydevd_attach_to_process")
@@ -380,7 +380,7 @@ def test_find_main_thread_id():
subprocess.check_call([sys.executable, "-m", "_pydevd_test_find_main_thread_id"], env=environ, cwd=cwd)
- resources_dir = os.path.join(os.path.dirname(pydevd.__file__), "tests_python", "resources")
+ resources_dir = os.path.join(os.path.dirname(__file__), "resources")
subprocess.check_call([sys.executable, os.path.join(resources_dir, "_pydevd_test_find_main_thread_id.py")], env=environ, cwd=cwd)
|