debugpy/tests/__init__.py
Pavel Minaev e94980f86c Do not load ptvsd.server (and hence, pydevd) unless the subpackage is loaded explicitly or via a public API entrypoint that requires it.
Move docstrings to top-level package, and update them to reflect the current behavior.

Remove unused code in ptvsd.common.log.

Move sys.path/prefix/site_packages logging into ptvsd.common.log, and log it from adapter and server to the same level of detail as the tests.

Fix injected code snipped for attach-by-PID.

Fix some Unicode issues in adapter and tests.

Refactor Timeline, debug.Session, and start methods.
2019-08-18 11:43:23 -07:00

73 lines
2.2 KiB
Python

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.
from __future__ import absolute_import, print_function, unicode_literals
"""ptvsd tests
"""
import pkgutil
import pytest
import py.path
import sys
# Do not import anything from ptvsd until assert rewriting is enabled below!
root = py.path.local(__file__) / ".."
test_data = root / "test_data"
"""A py.path.local object for the tests/test_data/ directory.
Idiomatic use is via from .. import::
from tests import test_data
f = open(str(test_data / "attach" / "attach1.py"))
"""
# This is only imported to ensure that the module is actually installed and the
# timeout setting in pytest.ini is active, since otherwise most timeline-based
# tests will hang indefinitely if they time out.
import pytest_timeout # noqa
# We want pytest to rewrite asserts (for better error messages) in the common code
# code used by the tests, and in all the test helpers. This does not affect ptvsd
# inside debugged processes.
def _register_assert_rewrite(modname):
modname = str(modname)
# print("pytest.register_assert_rewrite({0!r})".format(modname))
pytest.register_assert_rewrite(modname)
_register_assert_rewrite("ptvsd.common")
tests_submodules = pkgutil.iter_modules([str(root)])
for _, submodule, _ in tests_submodules:
submodule = str("{0}.{1}".format(__name__, submodule))
_register_assert_rewrite(submodule)
# Now we can import these, and pytest will rewrite asserts in them.
from ptvsd.common import json, log
import ptvsd.server # noqa
# Enable full logging to stderr, and make timestamps shorter to match maximum test
# run time better.
log.stderr = sys.stderr # use pytest-captured stderr rather than __stderr__
log.stderr_levels = set(log.LEVELS)
log.timestamp_format = "06.3f"
log.filename_prefix = "tests"
log.to_file()
# Enable JSON serialization for py.path.local.
def json_default(self, obj):
if isinstance(obj, py.path.local):
return obj.strpath
return self.original_default(obj)
json.JsonEncoder.original_default = json.JsonEncoder.default
json.JsonEncoder.default = json_default