aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/python/grpcio_tests/tests/unit/_logging_test.py
diff options
context:
space:
mode:
authorGravatar Richard Belleville <rbellevi@google.com>2018-10-31 16:45:54 -0700
committerGravatar Richard Belleville <rbellevi@google.com>2018-10-31 16:45:54 -0700
commit79d0424468d500a818384de8a5e056ec04bb7da3 (patch)
tree05aad704f45a8d6c91ee678a8636408ab667908c /src/python/grpcio_tests/tests/unit/_logging_test.py
parentb7335f5c011d9fad3570a097fb1165cc6fbd3cef (diff)
Pull out function to patch stderr
Diffstat (limited to 'src/python/grpcio_tests/tests/unit/_logging_test.py')
-rw-r--r--src/python/grpcio_tests/tests/unit/_logging_test.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/python/grpcio_tests/tests/unit/_logging_test.py b/src/python/grpcio_tests/tests/unit/_logging_test.py
index 662cd1ea9d..39c3afbfc8 100644
--- a/src/python/grpcio_tests/tests/unit/_logging_test.py
+++ b/src/python/grpcio_tests/tests/unit/_logging_test.py
@@ -21,21 +21,30 @@ import grpc
import functools
import sys
+def patch_stderr(f):
+ @functools.wraps(f)
+ def _impl(*args, **kwargs):
+ old_stderr = sys.stderr
+ sys.stderr = six.StringIO()
+ try:
+ f(args, kwargs)
+ finally:
+ sys.stderr = old_stderr
+ return _impl
+
class LoggingTest(unittest.TestCase):
def test_logger_not_occupied(self):
self.assertEqual(0, len(logging.getLogger().handlers))
+ @patch_stderr
def test_handler_found(self):
- old_stderr = sys.stderr
- sys.stderr = six.StringIO()
try:
reload_module(logging)
logging.basicConfig()
reload_module(grpc)
self.assertFalse("No handlers could be found" in sys.stderr.getvalue())
finally:
- sys.stderr = old_stderr
reload_module(logging)
if __name__ == '__main__':