debugpy/tests/logs.py
Pavel Minaev b3f0265785 Place pydevd log file in debug.Session log directory, for better handling of multi-session (e.g. multiproc) tests.
Always log to disk for test runs, and dump all ptvsd and pydevd logs on test failures and timeouts.
2019-10-16 11:44:17 -07:00

33 lines
1 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
import io
import os
import pytest_timeout
import sys
from ptvsd.common import log, options
def dump():
if options.log_dir is None:
return
log.info("Dumping logs from {0!j}", options.log_dir)
for dirpath, dirnames, filenames in os.walk(options.log_dir):
for name in filenames:
if not name.startswith("ptvsd") and not name.startswith("pydevd"):
continue
try:
path = os.path.join(dirpath, name)
with io.open(path, encoding="utf-8", errors="backslashreplace") as f:
s = f.read()
except Exception:
pass
else:
path = os.path.relpath(path, options.log_dir)
pytest_timeout.write_title(path)
print(s, file=sys.stderr)