mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Fix tests for Python 2.7.
This commit is contained in:
parent
c3d7d7a454
commit
42cd8a8367
6 changed files with 52 additions and 39 deletions
|
|
@ -237,6 +237,9 @@ all_launch = [
|
|||
launch["externalTerminal"],
|
||||
]
|
||||
|
||||
all_attach = [attach_by_socket["api"], attach_by_socket["cli"], attach_by_pid]
|
||||
all_attach = [attach_by_socket["api"], attach_by_socket["cli"]]
|
||||
if sys.version_info >= (3,):
|
||||
# Attach-by-PID is flaky on Python 2.7.
|
||||
all_attach += [attach_by_pid]
|
||||
|
||||
all = all_launch + all_attach
|
||||
|
|
|
|||
|
|
@ -313,6 +313,8 @@ class Session(object):
|
|||
for s in args
|
||||
]
|
||||
|
||||
cwd = compat.filename_str(cwd) if isinstance(cwd, py.path.local) else cwd
|
||||
|
||||
env = self._make_env(self.spawn_debuggee.env, codecov=False)
|
||||
env["PTVSD_LISTENER_FILE"] = self.listener_file = self.tmpdir / "listener"
|
||||
if debug_me is not None:
|
||||
|
|
|
|||
|
|
@ -391,6 +391,8 @@ def test_deep_stacks(pyfile, target, run):
|
|||
@pytest.mark.parametrize("target", targets.all)
|
||||
@pytest.mark.parametrize("func", ["breakpoint", "ptvsd.break_into_debugger"])
|
||||
def test_break_api(pyfile, target, run, func):
|
||||
if type(run).__name__ == "code" and sys.version_info < (3,):
|
||||
pytest.skip("https://github.com/microsoft/ptvsd/issues/1808")
|
||||
if func == "breakpoint" and sys.version_info < (3, 7):
|
||||
pytest.skip("breakpoint() was introduced in Python 3.7")
|
||||
|
||||
|
|
|
|||
|
|
@ -39,16 +39,18 @@ def test_exit_on_disconnect_for_launch(pyfile, target, run):
|
|||
@pyfile
|
||||
def code_to_debug():
|
||||
import debug_me # noqa
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
fp = os.path.join(os.path.dirname(os.path.abspath(__file__)), "here.txt") # @bp
|
||||
print("should not execute this")
|
||||
with open(fp, "w") as f:
|
||||
print("Should not continue after disconnect on launch", file=f)
|
||||
filename = sys.argv[1] # @bp
|
||||
# Disconnect happens here; subsequent lines should not run.
|
||||
with open(filename, "w") as f:
|
||||
f.write("failed")
|
||||
|
||||
filename = (code_to_debug.dirpath() / "failed.txt").strpath
|
||||
|
||||
with debug.Session() as session:
|
||||
session.expected_exit_code = some.int
|
||||
with run(session, target(code_to_debug)):
|
||||
with run(session, target(code_to_debug, args=[filename])):
|
||||
session.set_breakpoints(code_to_debug, all)
|
||||
|
||||
session.wait_for_stop(
|
||||
|
|
@ -56,5 +58,4 @@ def test_exit_on_disconnect_for_launch(pyfile, target, run):
|
|||
)
|
||||
session.disconnect()
|
||||
|
||||
fp = os.path.join(os.path.dirname(os.path.abspath(code_to_debug)), "here.txt")
|
||||
assert not os.path.exists(fp)
|
||||
assert not os.path.exists(filename)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
|
||||
import platform
|
||||
import pytest
|
||||
import sys
|
||||
|
||||
from ptvsd.common import compat
|
||||
from tests import code, debug, log, net, test_data
|
||||
|
|
@ -135,20 +134,19 @@ def test_flask_template_exception_no_multiproc(start_flask):
|
|||
}
|
||||
)
|
||||
|
||||
session.request_continue()
|
||||
|
||||
log.info("Exception will be reported again in {0}", paths.app_py)
|
||||
session.wait_for_stop("exception")
|
||||
session.request_continue()
|
||||
|
||||
# In Python 2, Flask reports this exception one more time, and it is
|
||||
# reported for both frames again.
|
||||
if sys.version_info < (3,):
|
||||
log.info("Exception gets double-reported in Python 2.")
|
||||
session.wait_for_stop("exception")
|
||||
session.request_continue()
|
||||
session.wait_for_stop("exception")
|
||||
# Exception gets reported again as it is re-raised in every frame between
|
||||
# the template and app.py. The number of frames is a Flask implementation
|
||||
# detail, and varies between versions, so we keep iterating until we see
|
||||
# it reported in app.py.
|
||||
while True:
|
||||
log.info("Exception propagating to next frame...")
|
||||
session.request_continue()
|
||||
stop = session.wait_for_stop("exception")
|
||||
if stop.frames[0] == some.dap.frame(paths.app_py, line=some.int):
|
||||
break
|
||||
|
||||
# Let the request finish processing and respond with HTTP 500.
|
||||
session.request_continue()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exc_type", ["handled", "unhandled"])
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import pytest
|
|||
import sys
|
||||
|
||||
import ptvsd
|
||||
from ptvsd.common import log
|
||||
from tests import debug
|
||||
from tests.patterns import some
|
||||
|
||||
|
|
@ -29,22 +30,27 @@ def expected_system_info():
|
|||
|
||||
return some.dict.containing(
|
||||
{
|
||||
"ptvsd": {"version": ptvsd.__version__},
|
||||
"python": {
|
||||
"version": version_str(sys.version_info),
|
||||
"implementation": {
|
||||
"name": impl_name,
|
||||
"version": impl_version,
|
||||
"description": some.str,
|
||||
},
|
||||
},
|
||||
"platform": {"name": sys.platform},
|
||||
"process": {
|
||||
"pid": some.int,
|
||||
"ppid": some.int,
|
||||
"executable": sys.executable,
|
||||
"bitness": 64 if sys.maxsize > 2 ** 32 else 32,
|
||||
},
|
||||
"ptvsd": some.dict.containing({"version": ptvsd.__version__}),
|
||||
"python": some.dict.containing(
|
||||
{
|
||||
"version": version_str(sys.version_info),
|
||||
"implementation": some.dict.containing(
|
||||
{
|
||||
"name": impl_name,
|
||||
"version": impl_version,
|
||||
"description": some.str,
|
||||
}
|
||||
),
|
||||
}
|
||||
),
|
||||
"platform": some.dict.containing({"name": sys.platform}),
|
||||
"process": some.dict.containing(
|
||||
{
|
||||
"pid": some.int,
|
||||
"executable": sys.executable,
|
||||
"bitness": 64 if sys.maxsize > 2 ** 32 else 32,
|
||||
}
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -64,6 +70,7 @@ def test_ptvsd_systemInfo(pyfile, target, run, expected_system_info):
|
|||
session.wait_for_stop()
|
||||
|
||||
system_info = session.request("ptvsd_systemInfo")
|
||||
log.info("Expected system info: {0}", expected_system_info)
|
||||
assert system_info == expected_system_info
|
||||
|
||||
session.request_continue()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue