diff options
author | Zuul <zuul@review.opendev.org> | 2019-07-10 23:27:18 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-07-10 23:27:18 +0000 |
commit | 495683d867217eff99d9deab5b4e2bd582f77c00 (patch) | |
tree | 61ba9730e00b4638f3ab06b0e434a45121b4737f | |
parent | 2fcd4d872713dc30e7352845c37515280f1d21ab (diff) | |
parent | 01f5a9f3af3a1630297a92dff0f998b4f0e97a49 (diff) | |
download | python-swiftclient-495683d867217eff99d9deab5b4e2bd582f77c00.tar.gz |
Merge "Support pdb in tests better"
-rw-r--r-- | tests/unit/utils.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/unit/utils.py b/tests/unit/utils.py index 8081501..025a234 100644 --- a/tests/unit/utils.py +++ b/tests/unit/utils.py @@ -20,6 +20,7 @@ from time import sleep import unittest import mock import six +import os from six.moves import reload_module from six.moves.urllib.parse import urlparse, ParseResult 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 # swiftclient.multithreading self.capture_output = CaptureOutput() - self.capture_output.__enter__() + 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 def fake_http_connection(*args, **kwargs): self.validateMockedRequestsConsumed() @@ -391,7 +404,6 @@ class MockHttpTest(unittest.TestCase): # un-hygienic mocking on the swiftclient.client module; which may lead # to some unfortunate test order dependency bugs by way of the broken # window theory if any other modules are similarly patched - self.capture_output.__exit__() reload_module(c) |