mirror of
https://github.com/microsoft/debugpy.git
synced 2025-12-23 08:48:12 +00:00
Remove prints in tests outside of the code being debugged - use logging instead.
This commit is contained in:
parent
8d189c8e91
commit
c511e98b02
6 changed files with 11 additions and 75 deletions
|
|
@ -1,4 +0,0 @@
|
|||
ANY = None
|
||||
Path = None
|
||||
Regex = None
|
||||
Is = None
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
# 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
|
||||
|
||||
"""When imported using from, this module effectively overrides the print() built-in
|
||||
with a synchronized version that also adds a timestamp.
|
||||
|
||||
Because tests can run in parallel, all modules that can be invoked from test code,
|
||||
and that need to print, should do::
|
||||
|
||||
from tests import print
|
||||
|
||||
Each call to print() is then atomic - i.e. it will not interleave with any other print.
|
||||
If a sequence of several print calls must be atomic, lock explicitly::
|
||||
|
||||
with print:
|
||||
print('fizz')
|
||||
print('bazz')
|
||||
"""
|
||||
|
||||
import sys
|
||||
import types
|
||||
|
||||
from ptvsd.common import fmt, singleton, timestamp
|
||||
|
||||
|
||||
# The class of the module object for this module.
|
||||
class Printer(singleton.ThreadSafeSingleton, types.ModuleType):
|
||||
def __init__(self):
|
||||
# Set self up as a proper module, and copy globals.
|
||||
# types must be re-imported, because globals aren't there yet at this point.
|
||||
import types
|
||||
types.ModuleType.__init__(self, __name__)
|
||||
self.__dict__.update(sys.modules[__name__].__dict__)
|
||||
|
||||
@singleton.autolocked_method
|
||||
def __call__(self, *args, **kwargs):
|
||||
"""Like builtin print(), but synchronized across multiple threads,
|
||||
and adds a timestamp.
|
||||
"""
|
||||
with self:
|
||||
timestamped = kwargs.pop('timestamped', True)
|
||||
t = timestamp.current() if timestamped else None
|
||||
if t is not None:
|
||||
t = '@%09.6f:' % t
|
||||
args = (t,) + args
|
||||
print(*args, **kwargs)
|
||||
|
||||
def f(self, format_string, *args, **kwargs) :
|
||||
"""Same as print(fmt(...)).
|
||||
"""
|
||||
return self(fmt(format_string, *args, **kwargs))
|
||||
|
||||
|
||||
# Replace the standard module object for this module with a Printer object.
|
||||
sys.modules[__name__] = Printer()
|
||||
|
|
@ -17,7 +17,7 @@ import socket
|
|||
import threading
|
||||
import time
|
||||
|
||||
from ptvsd.common import fmt, messaging
|
||||
from ptvsd.common import log, messaging
|
||||
from tests.patterns import some
|
||||
|
||||
|
||||
|
|
@ -576,14 +576,14 @@ class TestJsonMessageChannel(object):
|
|||
|
||||
class Handlers(object):
|
||||
def stackTrace_request(self, request):
|
||||
print(request.arguments["AAA"])
|
||||
print(request.arguments["AAA"]["BBB"])
|
||||
request.arguments["AAA"]
|
||||
request.arguments["AAA"]["BBB"]
|
||||
|
||||
def request(self, request):
|
||||
print(request.arguments["CCC"])
|
||||
request.arguments["CCC"]
|
||||
|
||||
def pause_request(self, request):
|
||||
print(request.arguments["DDD"])
|
||||
request.arguments["DDD"]
|
||||
|
||||
input, input_exhausted = self.iter_with_event(REQUESTS)
|
||||
output = []
|
||||
|
|
@ -732,9 +732,7 @@ class TestJsonMessageChannel(object):
|
|||
|
||||
# Spin until we receive "done", and also get responses to all requests.
|
||||
requests_sent = types.count("request")
|
||||
print(
|
||||
fmt("{0} waiting for {1} responses ...", self.name, requests_sent)
|
||||
)
|
||||
log.info("{0} waiting for {1} responses...", self.name, requests_sent)
|
||||
while True:
|
||||
with self.lock:
|
||||
if self.done:
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ from __future__ import absolute_import, print_function, unicode_literals
|
|||
|
||||
import pytest
|
||||
|
||||
from ptvsd.common import log
|
||||
from ptvsd.common.compat import reload
|
||||
from ptvsd.server import options, __main__
|
||||
from tests.patterns import some
|
||||
|
|
@ -64,7 +65,7 @@ def test_targets(target_kind, client, wait, nodebug, multiproc, extra):
|
|||
else:
|
||||
extra = []
|
||||
|
||||
print(args)
|
||||
log.debug("args = {0!r}", args)
|
||||
reload(options)
|
||||
rest = __main__.parse(args)
|
||||
assert list(rest) == extra
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ def test_set_next_statement(pyfile, start_method, run_as):
|
|||
func()
|
||||
|
||||
line_numbers = code_to_debug.lines
|
||||
print(line_numbers)
|
||||
|
||||
with debug.Session() as session:
|
||||
session.initialize(
|
||||
|
|
|
|||
|
|
@ -452,14 +452,14 @@ def test_unobserved(make_timeline, daemon):
|
|||
worker_can_proceed.wait()
|
||||
worker_can_proceed.clear()
|
||||
timeline.record_event(messages.event('dum', {}))
|
||||
print('dum')
|
||||
log.debug('dum')
|
||||
|
||||
worker_can_proceed.wait()
|
||||
timeline.record_event(messages.event('dee', {}))
|
||||
print('dee')
|
||||
log.debug('dee')
|
||||
|
||||
timeline.record_event(messages.event('dum', {}))
|
||||
print('dum')
|
||||
log.debug('dum')
|
||||
|
||||
timeline.freeze()
|
||||
assert timeline.is_frozen
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue