aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Richard Belleville <rbellevi@google.com>2018-11-01 13:24:03 -0700
committerGravatar Richard Belleville <rbellevi@google.com>2018-11-01 13:24:03 -0700
commitcf624a98e6a3e0f54c1028eb2db4a2f91f86a924 (patch)
tree77aae66a930378d7e5c4c258a25bf798c39a9f17
parentdc05e31ff1f442e252ef349e5a2c0dba346b38de (diff)
Isolate logging in all test cases
-rw-r--r--src/python/grpcio_tests/tests/unit/_logging_test.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/src/python/grpcio_tests/tests/unit/_logging_test.py b/src/python/grpcio_tests/tests/unit/_logging_test.py
index cc814ba46b..d1384effde 100644
--- a/src/python/grpcio_tests/tests/unit/_logging_test.py
+++ b/src/python/grpcio_tests/tests/unit/_logging_test.py
@@ -36,32 +36,38 @@ def patch_stderr(f):
return _impl
+def isolated_logging(f):
+
+ @functools.wraps(f)
+ def _impl(*args, **kwargs):
+ reload_module(logging)
+ reload_module(grpc)
+ try:
+ f(*args, **kwargs)
+ finally:
+ reload_module(logging)
+
+ return _impl
+
+
class LoggingTest(unittest.TestCase):
+ @isolated_logging
def test_logger_not_occupied(self):
self.assertEqual(0, len(logging.getLogger().handlers))
@patch_stderr
+ @isolated_logging
def test_handler_found(self):
- try:
- reload_module(logging)
- reload_module(grpc)
- self.assertFalse(
- "No handlers could be found" in sys.stderr.getvalue())
- finally:
- reload_module(logging)
+ self.assertEqual(0, len(sys.stderr.getvalue()))
+ @isolated_logging
def test_can_configure_logger(self):
- reload_module(logging)
- reload_module(grpc)
- try:
- intended_stream = six.StringIO()
- logging.basicConfig(stream=intended_stream)
- self.assertEqual(1, len(logging.getLogger().handlers))
- self.assertTrue(
- logging.getLogger().handlers[0].stream is intended_stream)
- finally:
- reload_module(logging)
+ intended_stream = six.StringIO()
+ logging.basicConfig(stream=intended_stream)
+ self.assertEqual(1, len(logging.getLogger().handlers))
+ self.assertTrue(
+ logging.getLogger().handlers[0].stream is intended_stream)
if __name__ == '__main__':