From 55eac82c9606d9b6f826a587329cb79e75218d74 Mon Sep 17 00:00:00 2001 From: Pavel Minaev Date: Fri, 24 Jan 2020 22:06:42 -0800 Subject: [PATCH] Fix #1811: tests using attach_by_pid fail on Python 2.7 Don't call enable_attach() and wait_for_attach() while under import lock. --- .../{debug_me => debuggee}/__init__.py | 25 ++++---------- .../{debug_me => debuggee}/backchannel.py | 4 +-- tests/debug/comms.py | 6 ++-- tests/debug/runners.py | 22 ++++++------ tests/debug/session.py | 6 ++-- tests/debugpy/test_args.py | 6 ++-- tests/debugpy/test_attach.py | 14 ++++++-- tests/debugpy/test_breakpoints.py | 34 +++++++++++++------ tests/debugpy/test_completions.py | 7 ++-- tests/debugpy/test_disconnect.py | 7 ++-- tests/debugpy/test_evaluate.py | 29 +++++++++++----- tests/debugpy/test_exception.py | 25 ++++++++++---- tests/debugpy/test_exclude_rules.py | 10 ++++-- tests/debugpy/test_flask.py | 2 +- tests/debugpy/test_justmycode.py | 3 +- tests/debugpy/test_log.py | 8 +++-- tests/debugpy/test_multiproc.py | 28 +++++++-------- tests/debugpy/test_output.py | 12 ++++--- tests/debugpy/test_path_mapping.py | 8 +++-- tests/debugpy/test_run.py | 15 +++++--- tests/debugpy/test_source_mapping.py | 4 ++- tests/debugpy/test_step.py | 4 ++- tests/debugpy/test_stop_on_entry.py | 4 +-- tests/debugpy/test_system_info.py | 4 ++- tests/debugpy/test_threads.py | 11 ++++-- tests/debugpy/test_tracing.py | 4 ++- tests/debugpy/test_vs_specific.py | 8 +++-- tests/test_data/bp/a&b/test.py | 3 +- tests/test_data/bp/ನನ್ನ_ಸ್ಕ್ರಿಪ್ಟ್.py | 5 ++- tests/test_data/django1/app.py | 4 ++- tests/test_data/flask1/__init__.py | 4 ++- tests/test_data/flask1/app.py | 1 - tests/test_data/flask1/main.py | 5 +-- tests/test_data/testpkgs/pkg1/sub/__main__.py | 4 ++- 34 files changed, 214 insertions(+), 122 deletions(-) rename tests/DEBUGGEE_PYTHONPATH/{debug_me => debuggee}/__init__.py (62%) rename tests/DEBUGGEE_PYTHONPATH/{debug_me => debuggee}/backchannel.py (96%) diff --git a/tests/DEBUGGEE_PYTHONPATH/debug_me/__init__.py b/tests/DEBUGGEE_PYTHONPATH/debuggee/__init__.py similarity index 62% rename from tests/DEBUGGEE_PYTHONPATH/debug_me/__init__.py rename to tests/DEBUGGEE_PYTHONPATH/debuggee/__init__.py index 59ff90ee..803fc4d7 100644 --- a/tests/DEBUGGEE_PYTHONPATH/debug_me/__init__.py +++ b/tests/DEBUGGEE_PYTHONPATH/debuggee/__init__.py @@ -8,14 +8,8 @@ from __future__ import absolute_import, division, print_function, unicode_litera to establish connection back to DebugSession in the test process, depending on DebugSession.start_method used by the test. -This module MUST be imported by all code that is executed via DebugSession, unless -it is launched with start_method="custom_client", for tests that need to set up -debugpy and establish the connection themselves in some special manner. - -If the code needs to access debugpy and/or pydevd, this module additionally exports -both as global variables, specifically so that it is possible to write:: - - from debug_me import debugpy, pydevd, backchannel +This module MUST be imported, and setup() must be called, by all test scripts that +are run via debug.Session and the standard runners. """ __all__ = ["debugpy", "pydevd", "session_id"] @@ -38,13 +32,8 @@ scratchpad = {} # Some runners require code to be executed in the debuggee process, either to set up # the debug server, or to ensure that it doesn't run any other code until the debugger # is attached. This provides a facility to inject such code. -_code = os.environ.pop("DEBUGPY_TEST_DEBUG_ME", None) -if _code: - _code = compile(_code, "", "exec") - eval(_code, {}) - - -# For `from debug_me import ...`. -import debugpy -import debugpy.server -import pydevd +def setup(): + _code = os.environ.pop("DEBUGPY_TEST_DEBUGGEE_SETUP", None) + if _code: + _code = compile(_code, "", "exec") + eval(_code, {}) diff --git a/tests/DEBUGGEE_PYTHONPATH/debug_me/backchannel.py b/tests/DEBUGGEE_PYTHONPATH/debuggee/backchannel.py similarity index 96% rename from tests/DEBUGGEE_PYTHONPATH/debug_me/backchannel.py rename to tests/DEBUGGEE_PYTHONPATH/debuggee/backchannel.py index 6abf0aaf..b67c33c0 100644 --- a/tests/DEBUGGEE_PYTHONPATH/debug_me/backchannel.py +++ b/tests/DEBUGGEE_PYTHONPATH/debuggee/backchannel.py @@ -14,7 +14,7 @@ import atexit import os import socket -import debug_me +import debuggee from debugpy.common import fmt, log, messaging @@ -54,7 +54,7 @@ class _stream: close = lambda: None -name = fmt("backchannel-{0}", debug_me.session_id) +name = fmt("backchannel-{0}", debuggee.session_id) port = os.environ.pop("DEBUGPY_TEST_BACKCHANNEL_PORT", None) if port is not None: port = int(port) diff --git a/tests/debug/comms.py b/tests/debug/comms.py index 690f25d5..de686900 100644 --- a/tests/debug/comms.py +++ b/tests/debug/comms.py @@ -117,8 +117,8 @@ class ScratchPad(object): raise NotImplementedError def __setitem__(self, key, value): - """Sets debug_me.scratchpad[key] = value inside the debugged process. + """Sets debuggee.scratchpad[key] = value inside the debugged process. """ - log.info("{0} debug_me.scratchpad[{1!r}] = {2!r}", self.session, key, value) - expr = fmt("sys.modules['debug_me'].scratchpad[{0!r}] = {1!r}", key, value) + log.info("{0} debuggee.scratchpad[{1!r}] = {2!r}", self.session, key, value) + expr = fmt("sys.modules['debuggee'].scratchpad[{0!r}] = {1!r}", key, value) self.session.request("evaluate", {"context": "repl", "expression": expr}) diff --git a/tests/debug/runners.py b/tests/debug/runners.py index 6f60b5ea..71b62dc6 100644 --- a/tests/debug/runners.py +++ b/tests/debug/runners.py @@ -146,8 +146,8 @@ def launch(session, target, console="integratedTerminal", cwd=None): def _attach_common_config(session, target, cwd): - assert target.code is None or "debug_me" in target.code, fmt( - "{0} must import debug_me.", target.filename + assert target.code is None or "debuggee.setup()" in target.code, fmt( + "{0} must invoke debuggee.setup().", target.filename ) target.configure(session) @@ -160,8 +160,6 @@ def _attach_common_config(session, target, cwd): @_runner @contextlib.contextmanager def attach_by_pid(session, target, cwd=None, wait=True): - if sys.version_info < (3,) and sys.platform == "win32": - pytest.skip("https://github.com/microsoft/ptvsd/issues/1811") if sys.version_info < (3,) and sys.platform == "darwin": pytest.skip("https://github.com/microsoft/ptvsd/issues/1916") if wait and not sys.platform.startswith("linux"): @@ -180,7 +178,7 @@ def attach_by_pid(session, target, cwd=None, wait=True): args = target.cli(session.spawn_debuggee.env) if wait: - debug_me = """ + debuggee_setup = """ import sys import threading import time @@ -188,15 +186,15 @@ import time while "debugpy" not in sys.modules: time.sleep(0.1) -from debug_me import scratchpad +from debuggee import scratchpad while "_attach_by_pid" not in scratchpad: time.sleep(0.1) """ else: - debug_me = None + debuggee_setup = None - session.spawn_debuggee(args, cwd=cwd, debug_me=debug_me) + session.spawn_debuggee(args, cwd=cwd, setup=debuggee_setup) config["processId"] = session.debuggee.pid session.spawn_adapter() @@ -230,22 +228,22 @@ def attach_by_socket( args += ["--host", compat.filename_str(host), "--port", str(port)] if log_dir is not None: args += ["--log-dir", log_dir] - debug_me = None + debuggee_setup = None elif method == "api": args = [] - debug_me = """ + debuggee_setup = """ import debugpy debugpy.enable_attach(({host!r}, {port!r}), {args}) if {wait!r}: debugpy.wait_for_attach() """ attach_args = "" if log_dir is None else fmt("log_dir={0!r}", log_dir) - debug_me = fmt(debug_me, host=host, port=port, wait=wait, args=attach_args) + debuggee_setup = fmt(debuggee_setup, host=host, port=port, wait=wait, args=attach_args) else: raise ValueError args += target.cli(session.spawn_debuggee.env) - session.spawn_debuggee(args, cwd=cwd, debug_me=debug_me) + session.spawn_debuggee(args, cwd=cwd, setup=debuggee_setup) if wait: session.wait_for_enable_attach() diff --git a/tests/debug/session.py b/tests/debug/session.py index f8f28678..057b3306 100644 --- a/tests/debug/session.py +++ b/tests/debug/session.py @@ -334,7 +334,7 @@ class Session(object): return env - def spawn_debuggee(self, args, cwd=None, exe=sys.executable, debug_me=None): + def spawn_debuggee(self, args, cwd=None, exe=sys.executable, setup=None): assert self.debuggee is None assert not len(self.captured_output - {"stdout", "stderr"}) @@ -349,8 +349,8 @@ class Session(object): env["DEBUGPY_ADAPTER_ENDPOINTS"] = self.adapter_endpoints = ( self.tmpdir / "adapter_endpoints" ) - if debug_me is not None: - env["DEBUGPY_TEST_DEBUG_ME"] = debug_me + if setup is not None: + env["DEBUGPY_TEST_DEBUGGEE_SETUP"] = setup log.info( "Spawning {0}:\n\n" diff --git a/tests/debugpy/test_args.py b/tests/debugpy/test_args.py index 51996963..c0070690 100644 --- a/tests/debugpy/test_args.py +++ b/tests/debugpy/test_args.py @@ -16,9 +16,11 @@ from tests.patterns import some def test_args(pyfile, target, run): @pyfile def code_to_debug(): - from debug_me import backchannel import sys - + import debuggee + from debuggee import backchannel + + debuggee.setup() backchannel.send(sys.argv) args = ["--arg1", "arg2", "-arg3", "--", "arg4", "-a"] diff --git a/tests/debugpy/test_attach.py b/tests/debugpy/test_attach.py index f37ba257..4ba7d180 100644 --- a/tests/debugpy/test_attach.py +++ b/tests/debugpy/test_attach.py @@ -18,10 +18,13 @@ from tests.patterns import some def test_attach_api(pyfile, target, wait_for_attach, is_attached, stop_method): @pyfile def code_to_debug(): - from debug_me import backchannel, debugpy, scratchpad + import debuggee + import debugpy import sys import time + from debuggee import backchannel, scratchpad + debuggee.setup() _, host, port, wait_for_attach, is_attached, stop_method = sys.argv port = int(port) debugpy.enable_attach((host, port)) @@ -91,9 +94,12 @@ def test_attach_api(pyfile, target, wait_for_attach, is_attached, stop_method): def test_reattach(pyfile, target, run): @pyfile def code_to_debug(): - from debug_me import debugpy, scratchpad import time + import debuggee + import debugpy + from debuggee import backchannel, scratchpad + debuggee.setup() debugpy.break_into_debugger() object() # @first @@ -134,9 +140,11 @@ def test_reattach(pyfile, target, run): def test_attach_by_pid(pyfile, target, pid_type): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import time + debuggee.setup() + def do_something(i): time.sleep(0.1) proceed = True diff --git a/tests/debugpy/test_breakpoints.py b/tests/debugpy/test_breakpoints.py index 5d10a2c8..0fdc7ef1 100644 --- a/tests/debugpy/test_breakpoints.py +++ b/tests/debugpy/test_breakpoints.py @@ -77,8 +77,9 @@ def test_conditional_breakpoint(pyfile, target, run, condition_kind, condition): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() for i in range(1, 10): print(i) # @bp @@ -110,16 +111,18 @@ def test_conditional_breakpoint(pyfile, target, run, condition_kind, condition): def test_crossfile_breakpoint(pyfile, target, run): @pyfile def script1(): - import debug_me # noqa + import debuggee + debuggee.setup() def do_something(): print("do something") # @bp @pyfile def script2(): - import debug_me # noqa + import debuggee import script1 + debuggee.setup() script1.do_something() # @bp print("Done") @@ -149,8 +152,9 @@ def test_error_in_condition(pyfile, target, run, error_name): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() for i in range(1, 10): # @bp pass @@ -180,9 +184,10 @@ def test_error_in_condition(pyfile, target, run, error_name): def test_log_point(pyfile, target, run, condition): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import sys + debuggee.setup() for i in range(0, 10): sys.stderr.write(str(i * 10) + "\n") # @bp sys.stderr.flush() @@ -257,8 +262,9 @@ def test_breakpoint_in_package_main(run): def test_add_and_remove_breakpoint(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() for i in range(0, 10): print(i) # @bp () # @wait_for_output @@ -290,7 +296,9 @@ def test_add_and_remove_breakpoint(pyfile, target, run): def test_breakpoint_in_nonexistent_file(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() with debug.Session() as session: with run(session, target(code_to_debug)): @@ -310,7 +318,9 @@ def test_breakpoint_in_nonexistent_file(pyfile, target, run): def test_invalid_breakpoints(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() # fmt: off b = True @@ -377,7 +387,9 @@ def test_invalid_breakpoints(pyfile, target, run): def test_deep_stacks(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() def deep_stack(level): if level <= 0: @@ -417,9 +429,11 @@ def test_break_api(pyfile, target, run, func): @pyfile def code_to_debug(): - from debug_me import debugpy # noqa + import debuggee + import debugpy import sys + debuggee.setup() func = eval(sys.argv[1]) func() print("break here") # @break diff --git a/tests/debugpy/test_completions.py b/tests/debugpy/test_completions.py index 324a187f..0c2c4d34 100644 --- a/tests/debugpy/test_completions.py +++ b/tests/debugpy/test_completions.py @@ -33,7 +33,9 @@ expected_at_line = { def test_completions_scope(pyfile, line, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() class SomeClass: def __init__(self, someVar): @@ -69,8 +71,9 @@ def test_completions_scope(pyfile, line, target, run): def test_completions_cases(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() a = 1 b = {"one": 1, "two": 2} c = 3 diff --git a/tests/debugpy/test_disconnect.py b/tests/debugpy/test_disconnect.py index 43bf250d..07e6cce0 100644 --- a/tests/debugpy/test_disconnect.py +++ b/tests/debugpy/test_disconnect.py @@ -16,8 +16,10 @@ from tests.patterns import some def test_continue_on_disconnect_for_attach(pyfile, target, run): @pyfile def code_to_debug(): - from debug_me import backchannel + import debuggee + from debuggee import backchannel + debuggee.setup() backchannel.send("continued") # @bp with debug.Session() as session: @@ -36,9 +38,10 @@ def test_continue_on_disconnect_for_attach(pyfile, target, run): def test_exit_on_disconnect_for_launch(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import sys + debuggee.setup() filename = sys.argv[1] # @bp # Disconnect happens here; subsequent lines should not run. with open(filename, "w") as f: diff --git a/tests/debugpy/test_evaluate.py b/tests/debugpy/test_evaluate.py index f34c1f37..95211f72 100644 --- a/tests/debugpy/test_evaluate.py +++ b/tests/debugpy/test_evaluate.py @@ -14,8 +14,9 @@ from tests.patterns import some def test_evaluate(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() a = 1 b = {"one": 1, 2: "two"} print(a, b) # @bp @@ -50,8 +51,9 @@ def test_evaluate(pyfile, target, run): def test_variables(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() a = 1 b = {"one": 1, 2: "two"} c = 3 @@ -113,8 +115,9 @@ def test_variables(pyfile, target, run): def test_variable_sort(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() b_test = {"spam": "A", "eggs": "B", "abcd": "C"} # noqa _b_test = 12 # noqa __b_test = 13 # noqa @@ -181,7 +184,9 @@ def test_variable_sort(pyfile, target, run): def test_return_values(pyfile, target, run, ret_vis): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() class MyClass(object): def do_something(self): @@ -253,11 +258,13 @@ def test_return_values(pyfile, target, run, ret_vis): def test_unicode(pyfile, target, run): @pyfile def code_to_debug(): - from debug_me import debugpy + import debuggee + import debugpy # Since Unicode variable name is a SyntaxError at parse time in Python 2, # this needs to do a roundabout way of setting it to avoid parse issues. globals()["\u16A0"] = 123 + debuggee.setup() debugpy.break_into_debugger() print("break") @@ -281,8 +288,9 @@ def test_unicode(pyfile, target, run): def test_hex_numbers(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() a = 100 b = [1, 10, 100] c = {10: 10, 100: 100, 1000: 1000} @@ -506,8 +514,11 @@ def test_hex_numbers(pyfile, target, run): def test_set_variable(pyfile, target, run): @pyfile def code_to_debug(): - from debug_me import backchannel, debugpy + import debuggee + import debugpy + from debuggee import backchannel + debuggee.setup() a = 1 debugpy.break_into_debugger() backchannel.send(a) @@ -548,8 +559,10 @@ def test_set_variable(pyfile, target, run): def test_set_expression(pyfile, target, run): @pyfile def code_to_debug(): - from debug_me import backchannel + import debuggee + from debuggee import backchannel + debuggee.setup() a = 1 backchannel.send(a) # @bp diff --git a/tests/debugpy/test_exception.py b/tests/debugpy/test_exception.py index bf33ec37..70c00e93 100644 --- a/tests/debugpy/test_exception.py +++ b/tests/debugpy/test_exception.py @@ -20,7 +20,9 @@ str_matching_ArithmeticError = some.str.matching(r"(.+\.)?ArithmeticError") def test_vsc_exception_options_raise_with_except(pyfile, target, run, raised, uncaught): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() def raise_with_except(): try: @@ -75,7 +77,9 @@ def test_vsc_exception_options_raise_without_except( ): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() def raise_without_except(): raise ArithmeticError("bad code") # @exc @@ -157,9 +161,10 @@ def test_vsc_exception_options_raise_without_except( def test_systemexit(pyfile, target, run, raised, uncaught, zero, exit_code): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import sys + debuggee.setup() exit_code = eval(sys.argv[1]) print("sys.exit(%r)" % (exit_code,)) try: @@ -231,8 +236,9 @@ def test_raise_exception_options(pyfile, target, run, exceptions, break_mode): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() raise AssertionError() # @AssertionError else: @@ -243,7 +249,9 @@ def test_raise_exception_options(pyfile, target, run, exceptions, break_mode): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() try: raise RuntimeError() # @RuntimeError @@ -299,9 +307,10 @@ def test_success_exitcodes( ): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import sys + debuggee.setup() exit_code = eval(sys.argv[1]) print("sys.exit(%r)" % (exit_code,)) sys.exit(exit_code) @@ -327,7 +336,9 @@ def test_success_exitcodes( def test_exception_stack(pyfile, target, run, max_frames): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() def do_something(n): if n <= 0: diff --git a/tests/debugpy/test_exclude_rules.py b/tests/debugpy/test_exclude_rules.py index 4323ec50..dde2c652 100644 --- a/tests/debugpy/test_exclude_rules.py +++ b/tests/debugpy/test_exclude_rules.py @@ -23,17 +23,19 @@ def test_exceptions_and_exclude_rules(pyfile, target, run, scenario, exc_type): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() raise RuntimeError("unhandled error") # @raise_line elif exc_type == "SystemExit": @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import sys + debuggee.setup() sys.exit(1) # @raise_line else: @@ -66,9 +68,11 @@ def test_exceptions_and_partial_exclude_rules(pyfile, target, run, scenario): @pyfile def code_to_debug(): - from debug_me import backchannel + import debuggee import sys + from debuggee import backchannel + debuggee.setup() call_me_back_dir = backchannel.receive() sys.path.insert(0, call_me_back_dir) diff --git a/tests/debugpy/test_flask.py b/tests/debugpy/test_flask.py index 5992913d..5cdbb0ce 100644 --- a/tests/debugpy/test_flask.py +++ b/tests/debugpy/test_flask.py @@ -57,7 +57,7 @@ def start_flask(run): args += ["--port", str(flask_server.port)] if multiprocess and run.request == "attach": - # For multiproc attach, we need to use a helper stub to import debug_me + # For multiproc attach, we need to use a helper stub to import debuggee # before running Flask; otherwise, we will get the connection only from # the subprocess, not from the Flask server process. target = targets.Program(paths.main_py, args=args) diff --git a/tests/debugpy/test_justmycode.py b/tests/debugpy/test_justmycode.py index e51ce0af..484620ef 100644 --- a/tests/debugpy/test_justmycode.py +++ b/tests/debugpy/test_justmycode.py @@ -16,8 +16,9 @@ from tests.patterns import some def test_justmycode_frames(pyfile, target, run, jmc): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() print("break here") # @bp with debug.Session() as session: diff --git a/tests/debugpy/test_log.py b/tests/debugpy/test_log.py index 7c39a0bc..d0c8e110 100644 --- a/tests/debugpy/test_log.py +++ b/tests/debugpy/test_log.py @@ -35,7 +35,9 @@ def check_logs(tmpdir, run): def test_log_dir(pyfile, tmpdir, target, method): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() # Depending on the method, attach_by_socket will use either `debugpy --log-dir ...` # or `enable_attach(log_dir=) ...`. @@ -53,8 +55,10 @@ def test_log_dir(pyfile, tmpdir, target, method): def test_log_dir_env(pyfile, tmpdir, run, target): @pyfile def code_to_debug(): - from debug_me import backchannel # noqa + import debuggee + from debuggee import backchannel + debuggee.setup() assert backchannel.receive() == "proceed" with check_logs(tmpdir, run): diff --git a/tests/debugpy/test_multiproc.py b/tests/debugpy/test_multiproc.py index c6515116..8718c42a 100644 --- a/tests/debugpy/test_multiproc.py +++ b/tests/debugpy/test_multiproc.py @@ -32,13 +32,15 @@ def test_multiprocessing(pyfile, target, run, start_method): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import multiprocessing import os import sys def parent(q, a): - from debug_me import backchannel + from debuggee import backchannel + + debuggee.setup() print("spawning child") p = multiprocessing.Process(target=child, args=(q, a)) @@ -146,7 +148,8 @@ def test_subprocess(pyfile, target, run): assert "debugpy" in sys.modules - from debug_me import backchannel, debugpy + import debugpy + from debuggee import backchannel backchannel.send(os.getpid()) backchannel.send(debugpy.__file__) @@ -154,11 +157,12 @@ def test_subprocess(pyfile, target, run): @pyfile def parent(): - import debug_me # noqa + import debuggee import os import subprocess import sys + debuggee.setup() argv = [sys.executable, sys.argv[1], "--arg1", "--arg2", "--arg3"] env = os.environ.copy() process = subprocess.Popen( @@ -209,8 +213,6 @@ def test_subprocess(pyfile, target, run): def test_autokill(pyfile, target): @pyfile def child(): - import debug_me # noqa - while True: pass @@ -250,8 +252,6 @@ def test_autokill(pyfile, target): def test_argv_quoting(pyfile, target, run): @pyfile def args(): - import debug_me # noqa - args = [ # noqa r"regular", r"", @@ -267,20 +267,19 @@ def test_argv_quoting(pyfile, target, run): @pyfile def parent(): - import debug_me # noqa - + import debuggee import sys import subprocess from args import args + debuggee.setup() child = sys.argv[1] subprocess.check_call([sys.executable] + [child] + args) @pyfile def child(): - from debug_me import backchannel import sys - + from debuggee import backchannel from args import args as expected_args backchannel.send(expected_args) @@ -314,12 +313,13 @@ def test_echo_and_shell(pyfile, target, run): @pyfile def code_to_run(): - import debug_me # noqa - + import debuggee import sys import subprocess import os + debuggee.setup() + if sys.platform == "win32": args = ["dir", "-c", "."] else: diff --git a/tests/debugpy/test_output.py b/tests/debugpy/test_output.py index a1840778..86be8d82 100644 --- a/tests/debugpy/test_output.py +++ b/tests/debugpy/test_output.py @@ -19,8 +19,9 @@ from tests.debug import runners def test_with_no_output(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() () # @wait_for_output with debug.Session() as session: @@ -42,8 +43,9 @@ def test_with_no_output(pyfile, target, run): def test_with_tab_in_output(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() a = "\t".join(("Hello", "World")) print(a) () # @wait_for_output @@ -65,8 +67,9 @@ def test_with_tab_in_output(pyfile, target, run): def test_redirect_output(pyfile, target, run, redirect): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + debuggee.setup() for i in [111, 222, 333, 444]: print(i) @@ -90,9 +93,10 @@ def test_redirect_output(pyfile, target, run, redirect): def test_non_ascii_output(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import sys + debuggee.setup() a = b"\xc3\xa9 \xc3\xa0 \xc3\xb6 \xc3\xb9\n" if sys.version_info[0] >= 3: sys.stdout.buffer.write(a) diff --git a/tests/debugpy/test_path_mapping.py b/tests/debugpy/test_path_mapping.py index 2c4deb2e..50b9f389 100644 --- a/tests/debugpy/test_path_mapping.py +++ b/tests/debugpy/test_path_mapping.py @@ -19,9 +19,11 @@ def target(request): def test_with_dot_remote_root(pyfile, long_tmpdir, target, run): @pyfile def code_to_debug(): - from debug_me import backchannel import os + import debuggee + from debuggee import backchannel + debuggee.setup() backchannel.send(os.path.abspath(__file__)) print("done") # @bp @@ -57,10 +59,12 @@ def test_with_dot_remote_root(pyfile, long_tmpdir, target, run): def test_with_path_mappings(pyfile, long_tmpdir, target, run): @pyfile def code_to_debug(): - from debug_me import backchannel + import debuggee import os import sys + from debuggee import backchannel + debuggee.setup() backchannel.send(os.path.abspath(__file__)) call_me_back_dir = backchannel.receive() sys.path.insert(0, call_me_back_dir) diff --git a/tests/debugpy/test_run.py b/tests/debugpy/test_run.py index 7cf1d03a..9509ec86 100644 --- a/tests/debugpy/test_run.py +++ b/tests/debugpy/test_run.py @@ -7,7 +7,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera import os import pytest import re -import sys import time import debugpy @@ -22,10 +21,13 @@ from tests.patterns import some def test_run(pyfile, target, run): @pyfile def code_to_debug(): - from debug_me import backchannel import os import sys + import debuggee + from debuggee import backchannel + + debuggee.setup() print("begin") backchannel.send(os.path.abspath(sys.modules["debugpy"].__file__)) assert backchannel.receive() == "continue" @@ -63,8 +65,10 @@ def test_run_submodule(run): def test_nodebug(pyfile, run, target): @pyfile def code_to_debug(): - from debug_me import backchannel + import debuggee + from debuggee import backchannel + debuggee.setup() backchannel.receive() # @ bp1 print("ok") # @ bp2 @@ -103,9 +107,12 @@ def test_wait_on_exit( ): @pyfile def code_to_debug(): - from debug_me import debugpy import sys + import debuggee + import debugpy + + debuggee.setup() debugpy.break_into_debugger() print() # line on which it'll actually break sys.exit(int(sys.argv[1])) diff --git a/tests/debugpy/test_source_mapping.py b/tests/debugpy/test_source_mapping.py index 21658958..b1b2c958 100644 --- a/tests/debugpy/test_source_mapping.py +++ b/tests/debugpy/test_source_mapping.py @@ -20,7 +20,9 @@ def run(request): def test_with_path_mappings(pyfile, tmpdir, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() def full_function(): # Note that this function is not called, it's there just to make the mapping explicit. diff --git a/tests/debugpy/test_step.py b/tests/debugpy/test_step.py index 64d03112..6d973178 100644 --- a/tests/debugpy/test_step.py +++ b/tests/debugpy/test_step.py @@ -13,7 +13,9 @@ from tests.patterns import some def test_set_next_statement(pyfile, run, target): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee + + debuggee.setup() def func(): print(1) # @inner1 diff --git a/tests/debugpy/test_stop_on_entry.py b/tests/debugpy/test_stop_on_entry.py index 349a8c44..7f55df5a 100644 --- a/tests/debugpy/test_stop_on_entry.py +++ b/tests/debugpy/test_stop_on_entry.py @@ -17,7 +17,7 @@ from tests.patterns import some def test_stop_on_entry(pyfile, run, target, breakpoint): @pyfile def code_to_debug(): - from debug_me import backchannel # @bp + from debuggee import backchannel # @bp backchannel.send("done") @@ -31,7 +31,7 @@ def test_stop_on_entry(pyfile, run, target, breakpoint): if breakpoint: stop = session.wait_for_stop( - "breakpoint", expected_frames=[some.dap.frame(code_to_debug, 1)] + "breakpoint", expected_frames=[some.dap.frame(code_to_debug, "bp")] ) session.request("next", {"threadId": stop.thread_id}) stop = session.wait_for_stop( diff --git a/tests/debugpy/test_system_info.py b/tests/debugpy/test_system_info.py index 1bc4eeb6..b9898bc3 100644 --- a/tests/debugpy/test_system_info.py +++ b/tests/debugpy/test_system_info.py @@ -58,8 +58,10 @@ def expected_system_info(): def test_debugpySystemInfo(pyfile, target, run, expected_system_info): @pyfile def code_to_debug(): - from debug_me import debugpy + import debuggee + import debugpy + debuggee.setup() debugpy.break_into_debugger() print() diff --git a/tests/debugpy/test_threads.py b/tests/debugpy/test_threads.py index 5bf13b0c..e5b89036 100644 --- a/tests/debugpy/test_threads.py +++ b/tests/debugpy/test_threads.py @@ -15,11 +15,12 @@ from tests import debug def test_thread_count(pyfile, target, run, count): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import threading import time import sys + debuggee.setup() stop = False def worker(tid, offset): @@ -56,9 +57,10 @@ def test_step_multi_threads(pyfile, target, run, resume): # so, when we step return on thread 1, the program should finish if all threads are resumed # or should keep waiting for the thread 2 to run if only thread 1 is resumed. - import debug_me # noqa + import debuggee import threading + debuggee.setup() event0 = threading.Event() event1 = threading.Event() event2 = threading.Event() @@ -135,10 +137,13 @@ def test_step_multi_threads(pyfile, target, run, resume): def test_debug_this_thread(pyfile, target, run): @pyfile def code_to_debug(): - from debug_me import debugpy + import debuggee + import debugpy import sys import threading + debuggee.setup() + def foo(x): debugpy.debug_this_thread() event.set() # @bp diff --git a/tests/debugpy/test_tracing.py b/tests/debugpy/test_tracing.py index 9ea153bb..acf1febf 100644 --- a/tests/debugpy/test_tracing.py +++ b/tests/debugpy/test_tracing.py @@ -11,9 +11,11 @@ from tests.patterns import some def test_tracing(pyfile, target, run): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee import debugpy + debuggee.setup() + def func(expected_tracing): assert debugpy.tracing() == expected_tracing, "inside func({0!r})".format( expected_tracing diff --git a/tests/debugpy/test_vs_specific.py b/tests/debugpy/test_vs_specific.py index e39b404a..444cac2b 100644 --- a/tests/debugpy/test_vs_specific.py +++ b/tests/debugpy/test_vs_specific.py @@ -16,9 +16,10 @@ from tests.timeline import Event def test_stack_format(pyfile, target, run, module, line): @pyfile def code_to_debug(): - import debug_me # noqa + import debuggee from test_module import do_something + debuggee.setup() do_something() @pyfile @@ -64,7 +65,10 @@ def test_module_events(pyfile, target, run): @pyfile def test_code(): - import debug_me # noqa + import debuggee + + debuggee.setup() + from module1 import do_something do_something() diff --git a/tests/test_data/bp/a&b/test.py b/tests/test_data/bp/a&b/test.py index 65263105..927a7b79 100644 --- a/tests/test_data/bp/a&b/test.py +++ b/tests/test_data/bp/a&b/test.py @@ -1,5 +1,6 @@ -import debug_me # noqa +import debuggee +debuggee.setup() print("one") # @one print("two") # @two print("three") # @three diff --git a/tests/test_data/bp/ನನ್ನ_ಸ್ಕ್ರಿಪ್ಟ್.py b/tests/test_data/bp/ನನ್ನ_ಸ್ಕ್ರಿಪ್ಟ್.py index 934acecc..ea4f8b37 100644 --- a/tests/test_data/bp/ನನ್ನ_ಸ್ಕ್ರಿಪ್ಟ್.py +++ b/tests/test_data/bp/ನನ್ನ_ಸ್ಕ್ರಿಪ್ಟ್.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- import sys -import debug_me # noqa +import debuggee + + def ಏನಾದರೂ_ಮಾಡು(): print('ಏನೋ ಮಾಡಿದೆ'.encode(sys.stdout.encoding, errors='replace')) # @bp +debuggee.setup() ಏನಾದರೂ_ಮಾಡು() diff --git a/tests/test_data/django1/app.py b/tests/test_data/django1/app.py index fb0cee49..aa40b091 100644 --- a/tests/test_data/django1/app.py +++ b/tests/test_data/django1/app.py @@ -1,4 +1,6 @@ -import debug_me # noqa +import debuggee + +debuggee.setup() import os import signal diff --git a/tests/test_data/flask1/__init__.py b/tests/test_data/flask1/__init__.py index 3ebe7301..67d9204f 100644 --- a/tests/test_data/flask1/__init__.py +++ b/tests/test_data/flask1/__init__.py @@ -1 +1,3 @@ -import debug_me # noqa +import debuggee + +debuggee.setup() diff --git a/tests/test_data/flask1/app.py b/tests/test_data/flask1/app.py index 9b067392..b0934e38 100644 --- a/tests/test_data/flask1/app.py +++ b/tests/test_data/flask1/app.py @@ -1,4 +1,3 @@ -import debug_me # noqa from flask import Flask from flask import render_template diff --git a/tests/test_data/flask1/main.py b/tests/test_data/flask1/main.py index ddd22890..5a72ec9d 100644 --- a/tests/test_data/flask1/main.py +++ b/tests/test_data/flask1/main.py @@ -1,8 +1,9 @@ -# For multiproc attach, we need to use a helper stub to import debug_me before running +# For multiproc attach, we need to use a helper stub to import debuggee before running # Flask; otherwise, we will get the connection only from the subprocess, not from the # Flask server process. -import debug_me # noqa +import debuggee import runpy +debuggee.setup() runpy.run_module("flask", run_name="__main__", alter_sys=True) diff --git a/tests/test_data/testpkgs/pkg1/sub/__main__.py b/tests/test_data/testpkgs/pkg1/sub/__main__.py index a3dc875d..4c284292 100644 --- a/tests/test_data/testpkgs/pkg1/sub/__main__.py +++ b/tests/test_data/testpkgs/pkg1/sub/__main__.py @@ -1,3 +1,5 @@ -from debug_me import backchannel +import debuggee +from debuggee import backchannel +debuggee.setup() backchannel.send("ok")