11# Standard library
22import contextlib
33import sys
4- import unittest
54
65# Third party
76import wrapt
1514
1615from tests .opentracer .utils import init_tracer
1716
18- from ...test_tracer import get_dummy_tracer
19- from ...util import assert_dict_issuperset , override_global_tracer , override_config
17+ from ...base import BaseTracerTestCase
18+ from ...util import assert_dict_issuperset , override_global_tracer
2019
2120if PY2 :
2221 from urllib2 import urlopen , build_opener , Request
@@ -39,16 +38,19 @@ def to_str(self, value):
3938 return value .decode ('utf-8' )
4039
4140 def setUp (self ):
41+ super (HTTPLibBaseMixin , self ).setUp ()
42+
4243 patch ()
43- self .tracer = get_dummy_tracer ()
4444 Pin .override (httplib , tracer = self .tracer )
4545
4646 def tearDown (self ):
4747 unpatch ()
4848
49+ super (HTTPLibBaseMixin , self ).tearDown ()
50+
4951
5052# Main test cases for httplib/http.client and urllib2/urllib.request
51- class HTTPLibTestCase (HTTPLibBaseMixin , unittest . TestCase ):
53+ class HTTPLibTestCase (HTTPLibBaseMixin , BaseTracerTestCase ):
5254 SPAN_NAME = 'httplib.request' if PY2 else 'http.client.request'
5355
5456 def to_str (self , value ):
@@ -65,13 +67,6 @@ def get_https_connection(self, *args, **kwargs):
6567 Pin .override (conn , tracer = self .tracer )
6668 return conn
6769
68- def setUp (self ):
69- patch ()
70- self .tracer = get_dummy_tracer ()
71-
72- def tearDown (self ):
73- unpatch ()
74-
7570 def test_patch (self ):
7671 """
7772 When patching httplib
@@ -354,7 +349,7 @@ def test_httplib_request_and_response_headers(self):
354349 self .assertEqual (s .get_tag ('http.response.headers.access_control_allow_origin' ), None )
355350
356351 # Enabled when configured
357- with override_config ('hhtplib' , {}):
352+ with self . override_config ('hhtplib' , {}):
358353 integration_config = config .httplib # type: IntegrationConfig
359354 integration_config .http .trace_headers (['my-header' , 'access-control-allow-origin' ])
360355 conn = self .get_http_connection (SOCKET )
@@ -502,7 +497,7 @@ def test_httplib_request_get_request_ot(self):
502497if PY2 :
503498 import urllib
504499
505- class HTTPLibPython2Test (HTTPLibBaseMixin , unittest . TestCase ):
500+ class HTTPLibPython2Test (HTTPLibBaseMixin , BaseTracerTestCase ):
506501 def test_urllib_request (self ):
507502 """
508503 When making a request via urllib.urlopen
0 commit comments