test: make CaptureOutput easier to debug
Change-Id: I7c610abbc33e7fbe9a3dcbe2bda856f0aed599c0
This commit is contained in:
parent
ce4fb27b53
commit
7844fb9e0a
|
@ -216,19 +216,8 @@ class MockHttpTest(unittest.TestCase):
|
|||
# won't cover the references to sys.stdout/sys.stderr in
|
||||
# swiftclient.multithreading
|
||||
self.capture_output = CaptureOutput()
|
||||
if 'SWIFTCLIENT_DEBUG' not in os.environ:
|
||||
self.capture_output.__enter__()
|
||||
self.addCleanup(self.capture_output.__exit__)
|
||||
|
||||
# since we're going to steal all stderr output globally; we should
|
||||
# give the developer an escape hatch or risk scorn
|
||||
def blowup_but_with_the_helpful(*args, **kwargs):
|
||||
raise Exception(
|
||||
"You tried to enter a debugger while stderr is "
|
||||
"patched, you need to set SWIFTCLIENT_DEBUG=1 "
|
||||
"and try again")
|
||||
import pdb
|
||||
pdb.set_trace = blowup_but_with_the_helpful
|
||||
self.capture_output.__enter__()
|
||||
self.addCleanup(self.capture_output.__exit__)
|
||||
|
||||
def fake_http_connection(*args, **kwargs):
|
||||
self.validateMockedRequestsConsumed()
|
||||
|
@ -482,8 +471,19 @@ class CaptureOutput(object):
|
|||
]
|
||||
|
||||
def __enter__(self):
|
||||
for patcher in self.patchers:
|
||||
patcher.start()
|
||||
if 'SWIFTCLIENT_DEBUG' not in os.environ:
|
||||
# since we're going to steal all stderr output globally; we should
|
||||
# give the developer an escape hatch or risk scorn
|
||||
def blowup_but_with_the_helpful(*args, **kwargs):
|
||||
raise Exception(
|
||||
"You tried to enter a debugger while stderr is "
|
||||
"patched, you need to set SWIFTCLIENT_DEBUG=1 "
|
||||
"and try again")
|
||||
import pdb
|
||||
pdb.set_trace = blowup_but_with_the_helpful
|
||||
|
||||
for patcher in self.patchers:
|
||||
patcher.start()
|
||||
return self
|
||||
|
||||
def __exit__(self, *args, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue