Merge "Support pdb in tests better"
This commit is contained in:
@@ -20,6 +20,7 @@ from time import sleep
|
|||||||
import unittest
|
import unittest
|
||||||
import mock
|
import mock
|
||||||
import six
|
import six
|
||||||
|
import os
|
||||||
from six.moves import reload_module
|
from six.moves import reload_module
|
||||||
from six.moves.urllib.parse import urlparse, ParseResult
|
from six.moves.urllib.parse import urlparse, ParseResult
|
||||||
from swiftclient import client as c
|
from swiftclient import client as c
|
||||||
@@ -212,7 +213,19 @@ class MockHttpTest(unittest.TestCase):
|
|||||||
# won't cover the references to sys.stdout/sys.stderr in
|
# won't cover the references to sys.stdout/sys.stderr in
|
||||||
# swiftclient.multithreading
|
# swiftclient.multithreading
|
||||||
self.capture_output = CaptureOutput()
|
self.capture_output = CaptureOutput()
|
||||||
|
if 'SWIFTCLIENT_DEBUG' not in os.environ:
|
||||||
self.capture_output.__enter__()
|
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
|
||||||
|
|
||||||
def fake_http_connection(*args, **kwargs):
|
def fake_http_connection(*args, **kwargs):
|
||||||
self.validateMockedRequestsConsumed()
|
self.validateMockedRequestsConsumed()
|
||||||
@@ -391,7 +404,6 @@ class MockHttpTest(unittest.TestCase):
|
|||||||
# un-hygienic mocking on the swiftclient.client module; which may lead
|
# un-hygienic mocking on the swiftclient.client module; which may lead
|
||||||
# to some unfortunate test order dependency bugs by way of the broken
|
# to some unfortunate test order dependency bugs by way of the broken
|
||||||
# window theory if any other modules are similarly patched
|
# window theory if any other modules are similarly patched
|
||||||
self.capture_output.__exit__()
|
|
||||||
reload_module(c)
|
reload_module(c)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user