Skip to content

Commit c247e94

Browse files
Prevent the alteration of test env by logging handlers
1 parent ea3b6d5 commit c247e94

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lib/test/test_httplib.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ def create_connection(self, *pos, **kw):
128128
return FakeSocket(*self.fake_socket_args)
129129

130130
class HeaderTests(TestCase):
131+
132+
def setUp(self):
133+
self.handlers = logging.root.handlers
134+
self.saved_handlers = logging._handlers.copy()
135+
self.saved_handler_list = logging._handlerList[:]
136+
137+
def tearDown(self):
138+
logging._handlers.clear()
139+
logging._handlers.update(self.saved_handlers)
140+
logging._handlerList[:] = self.saved_handler_list
141+
131142
def test_auto_headers(self):
132143
# Some headers are added automatically, but should not be added by
133144
# .request() if they are explicitly set.
@@ -1878,8 +1889,14 @@ def setUp(self):
18781889
self.host = 'proxy.com'
18791890
self.conn = client.HTTPConnection(self.host)
18801891
self.conn._create_connection = self._create_connection(response_text)
1892+
self.handlers = logging.root.handlers
1893+
self.saved_handlers = logging._handlers.copy()
1894+
self.saved_handler_list = logging._handlerList[:]
18811895

18821896
def tearDown(self):
1897+
logging._handlers.clear()
1898+
logging._handlers.update(self.saved_handlers)
1899+
logging._handlerList[:] = self.saved_handler_list
18831900
self.conn.close()
18841901

18851902
def _create_connection(self, response_text):

0 commit comments

Comments
 (0)