diff --git a/pytest.ini b/pytest.ini index 229013d7..8cfc2eeb 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,5 +1,5 @@ [pytest] testpaths=tests -timeout=30 +timeout=20 timeout_method=thread addopts=-n8 diff --git a/src/ptvsd/adapter/ide.py b/src/ptvsd/adapter/ide.py index 7a8586c9..54d371a4 100644 --- a/src/ptvsd/adapter/ide.py +++ b/src/ptvsd/adapter/ide.py @@ -5,7 +5,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals import os -import platform import sys import ptvsd @@ -206,7 +205,7 @@ class IDE(components.Component, sockets.ClientConnection): elif {"UnixClient", "UNIX"} & debug_options: client_os_type = "UNIX" else: - client_os_type = "WINDOWS" if platform.system() == "Windows" else "UNIX" + client_os_type = "WINDOWS" if sys.platform == "win32" else "UNIX" self.server.channel.request( "setDebuggerProperty", { @@ -231,7 +230,7 @@ class IDE(components.Component, sockets.ClientConnection): sudo = request("sudo", json.default("Sudo" in self.session.debug_options)) if sudo: - if platform.system() == "Windows": + if sys.platform == "win32": raise request.cant_handle('"sudo":true is not supported on Windows.') else: if "Sudo" in self.session.debug_options: diff --git a/src/ptvsd/common/log.py b/src/ptvsd/common/log.py index 797b2db7..573b37c8 100644 --- a/src/ptvsd/common/log.py +++ b/src/ptvsd/common/log.py @@ -8,8 +8,8 @@ import contextlib import functools import inspect import io -import platform import os +import platform import sys import threading import traceback diff --git a/src/ptvsd/common/sockets.py b/src/ptvsd/common/sockets.py index af21d5f6..cf6c2a00 100644 --- a/src/ptvsd/common/sockets.py +++ b/src/ptvsd/common/sockets.py @@ -4,8 +4,8 @@ from __future__ import absolute_import, division, print_function, unicode_literals -import platform import socket +import sys import threading from ptvsd.common import log @@ -37,7 +37,7 @@ def create_client(): def _new_sock(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) - if platform.system() == "Windows": + if sys.platform == "win32": sock.setsockopt(socket.SOL_SOCKET, socket.SO_EXCLUSIVEADDRUSE, 1) else: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) diff --git a/src/ptvsd/launcher/adapter.py b/src/ptvsd/launcher/adapter.py index 1a67f0d3..d473d979 100644 --- a/src/ptvsd/launcher/adapter.py +++ b/src/ptvsd/launcher/adapter.py @@ -6,7 +6,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera import functools import os -import platform import sys import ptvsd @@ -51,7 +50,7 @@ class Handlers(object): cmdline = [] if property_or_debug_option("sudo", "Sudo"): - if platform.system() == "Windows": + if sys.platform == "win32": raise request.cant_handle('"sudo":true is not supported on Windows.') else: cmdline += ["sudo"] diff --git a/src/ptvsd/launcher/debuggee.py b/src/ptvsd/launcher/debuggee.py index 0a22e271..2f9cf767 100644 --- a/src/ptvsd/launcher/debuggee.py +++ b/src/ptvsd/launcher/debuggee.py @@ -7,7 +7,6 @@ from __future__ import absolute_import, division, print_function, unicode_litera import atexit import locale import os -import platform import struct import subprocess import sys @@ -114,7 +113,7 @@ def wait_for_exit(): try: code = process.wait() - if platform.system() != "Windows" and code < 0: + if sys.platform != "win32" and code < 0: # On POSIX, if the process was terminated by a signal, Popen will use # a negative returncode to indicate that - but the actual exit code of # the process is always an unsigned number, and can be determined by diff --git a/tests/debug/runners.py b/tests/debug/runners.py index efe07cac..cf448c83 100644 --- a/tests/debug/runners.py +++ b/tests/debug/runners.py @@ -53,7 +53,6 @@ If there is no configuration phase, the runner returns directly:: """ import os -import platform import pytest import sys @@ -159,7 +158,7 @@ def _attach_common_config(session, target, cwd): @_runner def attach_by_pid(session, target, cwd=None, wait=True): - if sys.version_info < (3,) and platform.system() == "Windows": + if sys.version_info < (3,) and sys.platform == "win32": pytest.skip("https://github.com/microsoft/ptvsd/issues/1811") log.info("Attaching {0} to {1} by PID.", session, target) diff --git a/tests/patterns/some.py b/tests/patterns/some.py index 67f3a35b..12ecabaf 100644 --- a/tests/patterns/some.py +++ b/tests/patterns/some.py @@ -48,7 +48,7 @@ Usage:: assert "abbc" != some.str.matching(r"ab") assert "abbc" != some.str.matching(r"bc") - if platform.system() == "Windows": + if sys.platform == "win32": assert "\\Foo\\Bar" == some.path("/foo/bar") else: assert "/Foo/Bar" != some.path("/foo/bar") diff --git a/tests/ptvsd/common/test_socket.py b/tests/ptvsd/common/test_socket.py index f490be21..03d53b62 100644 --- a/tests/ptvsd/common/test_socket.py +++ b/tests/ptvsd/common/test_socket.py @@ -4,8 +4,8 @@ from __future__ import absolute_import, division, print_function, unicode_literals -import platform import pytest +import sys from ptvsd.common import sockets @@ -15,7 +15,7 @@ class TestSocketServerReuse(object): # NOTE: Windows allows loopback range 127/8. Some flavors of Linux support # 127/8 range. Mac by default supports only 127/0. Configuring /etc/network/interface # for this one test is overkill so use '0.0.0.0' on Mac instead. - HOST2 = "127.0.0.2" if platform.system() in ["Windows", "Linux"] else "0.0.0.0" + HOST2 = "127.0.0.2" if sys.platform != "darwin" else "0.0.0.0" def test_reuse_same_address_port(self): # NOTE: This test should ensure that same address port can be used by two diff --git a/tests/ptvsd/server/test_attach.py b/tests/ptvsd/server/test_attach.py index a9b22634..0797e0e8 100644 --- a/tests/ptvsd/server/test_attach.py +++ b/tests/ptvsd/server/test_attach.py @@ -134,18 +134,27 @@ def test_attach_by_pid(pyfile, target): def do_something(i): time.sleep(0.1) + proceed = True print(i) # @bp + return proceed for i in range(100): - do_something(i) + if not do_something(i): + break with debug.Session() as session: with session.attach_by_pid(target(code_to_debug), wait=False): session.set_breakpoints(code_to_debug, all) - session.wait_for_stop(expected_frames=[some.dap.frame(code_to_debug, "bp")]) + stop = session.wait_for_stop( + expected_frames=[some.dap.frame(code_to_debug, "bp")] + ) # Remove breakpoint and continue. + session.request( + "setExpression", + {"frameId": stop.frame_id, "expression": "proceed", "value": "False"}, + ) session.set_breakpoints(code_to_debug, []) session.request_continue() session.wait_for_next( diff --git a/tests/ptvsd/server/test_breakpoints.py b/tests/ptvsd/server/test_breakpoints.py index 9316dd8d..698e9cbe 100644 --- a/tests/ptvsd/server/test_breakpoints.py +++ b/tests/ptvsd/server/test_breakpoints.py @@ -5,7 +5,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals -import platform import pytest import re import sys @@ -41,7 +40,7 @@ def test_path_with_ampersand(target, run): sys.version_info < (3, 0), reason="Paths are not Unicode in Python 2.7" ) @pytest.mark.skipif( - platform.system() == "Windows" and sys.version_info < (3, 6), + sys.platform == "win32" and sys.version_info < (3, 6), reason="https://github.com/Microsoft/ptvsd/issues/1124#issuecomment-459506802", ) @pytest.mark.parametrize("target", targets.all_named) diff --git a/tests/ptvsd/server/test_flask.py b/tests/ptvsd/server/test_flask.py index 5393cb16..c4584447 100644 --- a/tests/ptvsd/server/test_flask.py +++ b/tests/ptvsd/server/test_flask.py @@ -4,8 +4,8 @@ from __future__ import absolute_import, division, print_function, unicode_literals -import platform import pytest +import sys from ptvsd.common import compat from tests import code, debug, log, net, test_data @@ -43,8 +43,8 @@ def start_flask(run): "FLASK_DEBUG": "1" if multiprocess else "0", } ) - if platform.system() != "Windows": - locale = "en_US.utf8" if platform.system() == "Linux" else "en_US.UTF-8" + if sys.platform != "win32": + locale = "en_US.utf8" if sys.platform.startswith("linux") else "en_US.UTF-8" session.config.env.update({"LC_ALL": locale, "LANG": locale}) session.config.update({"jinja": True, "subProcess": multiprocess}) diff --git a/tests/ptvsd/server/test_multiproc.py b/tests/ptvsd/server/test_multiproc.py index a91e70db..e41ccf4e 100644 --- a/tests/ptvsd/server/test_multiproc.py +++ b/tests/ptvsd/server/test_multiproc.py @@ -4,7 +4,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals -import platform import pytest import sys @@ -14,6 +13,8 @@ from tests import debug from tests.debug import runners from tests.patterns import some +pytestmark = pytest.mark.timeout(30) + @pytest.fixture(params=[runners.launch, runners.attach_by_socket["api"]]) def run(request): @@ -25,11 +26,11 @@ def run(request): [""] if sys.version_info < (3,) else ["spawn"] - if platform.system() == "Windows" + if sys.platform == "win32" else ["spawn", "fork"], ) def test_multiprocessing(pyfile, target, run, start_method): - if start_method == "spawn" and platform.system() != "Windows": + if start_method == "spawn" and sys.platform != "win32": pytest.skip("https://github.com/microsoft/ptvsd/issues/1887") @pyfile @@ -204,7 +205,6 @@ def test_subprocess(pyfile, target, run): assert child_argv == [child, "--arg1", "--arg2", "--arg3"] -@pytest.mark.timeout(30) @pytest.mark.skip("Needs refactoring to use the new debug.Session API") @pytest.mark.parametrize( "start_method", [runners.launch, runners.attach_by_socket["cli"]] diff --git a/tests/ptvsd/server/test_threads.py b/tests/ptvsd/server/test_threads.py index 4798bc48..7b571aaf 100644 --- a/tests/ptvsd/server/test_threads.py +++ b/tests/ptvsd/server/test_threads.py @@ -4,8 +4,8 @@ from __future__ import absolute_import, division, print_function, unicode_literals -import platform import pytest +import sys import time from tests import debug @@ -129,14 +129,14 @@ def test_step_multi_threads(pyfile, target, run, resume): @pytest.mark.skipif( - platform.system() not in ["Windows", "Linux", "Darwin"], - reason="Test not implemented on " + platform.system(), + sys.platform not in ["win32", "darwin"] and not sys.platform.startswith("linux"), + reason="Test not implemented for sys.platform=" + repr(sys.platform), ) def test_debug_this_thread(pyfile, target, run): @pyfile def code_to_debug(): from debug_me import ptvsd - import platform + import sys import threading def foo(x): @@ -146,7 +146,7 @@ def test_debug_this_thread(pyfile, target, run): event = threading.Event() - if platform.system() == "Windows": + if sys.platform == "win32": from ctypes import CFUNCTYPE, c_void_p, c_size_t, c_uint32, windll thread_func_p = CFUNCTYPE(c_uint32, c_void_p) @@ -161,7 +161,7 @@ def test_debug_this_thread(pyfile, target, run): c_uint32(0), c_void_p(0), ) - elif platform.system() == "Linux" or platform.system() == "Darwin": + elif sys.platform == "darwin" or sys.platform.startswith("linux"): from ctypes import CDLL, CFUNCTYPE, byref, c_void_p, c_ulong from ctypes.util import find_library @@ -174,7 +174,7 @@ def test_debug_this_thread(pyfile, target, run): byref(c_ulong(0)), c_void_p(0), thread_func, c_void_p(0) ) else: - assert False + pytest.fail(sys.platform) event.wait() diff --git a/tests/pytest_fixtures.py b/tests/pytest_fixtures.py index f104d1f7..bbe8119d 100644 --- a/tests/pytest_fixtures.py +++ b/tests/pytest_fixtures.py @@ -6,9 +6,9 @@ from __future__ import absolute_import, division, print_function, unicode_litera import inspect import os -import platform import py import pytest +import sys import threading import types @@ -125,7 +125,7 @@ def daemon(request): assert not thread.is_alive() -if platform.system() != "Windows": +if sys.platform != "win32": @pytest.fixture def long_tmpdir(request, tmpdir): diff --git a/tests/watchdog/worker.py b/tests/watchdog/worker.py index a8d3077e..81f63fa7 100644 --- a/tests/watchdog/worker.py +++ b/tests/watchdog/worker.py @@ -151,16 +151,6 @@ def main(tests_pid): proc.pid, ) - # if platform.system() == "Linux": - # try: - # # gcore will automatically add pid to the filename - # core_file = os.path.join(tempfile.gettempdir(), "ptvsd_core") - # gcore_cmd = fmt("gcore -o {0} {1}", core_file, proc.pid) - # log.warning("WatchDog-{0}: {1}", tests_pid, gcore_cmd) - # os.system(gcore_cmd) - # except Exception: - # log.exception() - try: proc.kill() except psutil.NoSuchProcess: