Pull out function to patch stderr

pull/17119/head
Richard Belleville 6 years ago
parent 2acb85006a
commit e4b4f3131b
  1. 15
      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__':

Loading…
Cancel
Save