File: __init__.py

package info (click to toggle)
debugpy 1.8.19%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,452 kB
  • sloc: python: 14,840; sh: 185; makefile: 33
file content (83 lines) | stat: -rw-r--r-- 2,472 bytes parent folder | download | duplicates (3)
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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE in the project root
# for license information.

"""debugpy tests
"""

import os
import pkgutil
import py
import pytest

# Do not import anything from debugpy until assert rewriting is enabled below!

full = int(os.environ.get("DEBUGPY_TESTS_FULL", "0")) != 0

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 debugpy
# 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("debugpy.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 debugpy.common import json, log
import debugpy.server  # noqa

# Clean up environment variables that were automatically set when importing pydevd -
# we don't need them in the test runner process (since pydevd is not tracing it),
# and some tests must be able to spawn debuggee with them unset.
for name in (
    "DEBUGPY_LOG_DIR",
    "PYDEVD_DEBUG",
    "PYDEVD_DEBUG_FILE",
    "PYDEVD_USE_FRAME_EVAL",
):
    os.environ.pop(name, None)

# Enable full logging to stderr, and make timestamps shorter to match maximum test
# run time better.
log.stderr.levels = all
log.timestamp_format = "06.3f"
log.to_file(prefix="tests")


# 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