1111from ddtrace .contrib .httplib import patch , unpatch
1212from ddtrace .contrib .httplib .patch import should_skip_request
1313from ddtrace .pin import Pin
14+
15+ from .utils import override_global_tracer
1416from ...test_tracer import get_dummy_tracer
1517
18+
1619if PY2 :
1720 from urllib2 import urlopen , build_opener , Request
1821else :
@@ -316,7 +319,9 @@ def test_urllib_request(self):
316319 we return the original response
317320 we capture a span for the request
318321 """
319- resp = urlopen ('http://httpstat.us/200' )
322+ with override_global_tracer (self .tracer ):
323+ resp = urlopen ('http://httpstat.us/200' )
324+
320325 self .assertEqual (self .to_str (resp .read ()), '200 OK' )
321326 self .assertEqual (resp .getcode (), 200 )
322327
@@ -338,7 +343,9 @@ def test_urllib_request_https(self):
338343 we return the original response
339344 we capture a span for the request
340345 """
341- resp = urlopen ('https://httpbin.org/status/200' )
346+ with override_global_tracer (self .tracer ):
347+ resp = urlopen ('https://httpbin.org/status/200' )
348+
342349 self .assertEqual (self .to_str (resp .read ()), '' )
343350 self .assertEqual (resp .getcode (), 200 )
344351
@@ -361,7 +368,9 @@ def test_urllib_request_object(self):
361368 we capture a span for the request
362369 """
363370 req = Request ('http://httpstat.us/200' )
364- resp = urlopen (req )
371+ with override_global_tracer (self .tracer ):
372+ resp = urlopen (req )
373+
365374 self .assertEqual (self .to_str (resp .read ()), '200 OK' )
366375 self .assertEqual (resp .getcode (), 200 )
367376
@@ -383,7 +392,9 @@ def test_urllib_request_opener(self):
383392 we capture a span for the request
384393 """
385394 opener = build_opener ()
386- resp = opener .open ('http://httpstat.us/200' )
395+ with override_global_tracer (self .tracer ):
396+ resp = opener .open ('http://httpstat.us/200' )
397+
387398 self .assertEqual (self .to_str (resp .read ()), '200 OK' )
388399 self .assertEqual (resp .getcode (), 200 )
389400
@@ -410,7 +421,9 @@ def test_urllib_request(self):
410421 we return the original response
411422 we capture a span for the request
412423 """
413- resp = urllib .urlopen ('http://httpstat.us/200' )
424+ with override_global_tracer (self .tracer ):
425+ resp = urllib .urlopen ('http://httpstat.us/200' )
426+
414427 self .assertEqual (resp .read (), '200 OK' )
415428 self .assertEqual (resp .getcode (), 200 )
416429
@@ -432,7 +445,9 @@ def test_urllib_request_https(self):
432445 we return the original response
433446 we capture a span for the request
434447 """
435- resp = urllib .urlopen ('https://httpbin.org/status/200' )
448+ with override_global_tracer (self .tracer ):
449+ resp = urllib .urlopen ('https://httpbin.org/status/200' )
450+
436451 self .assertEqual (resp .read (), '' )
437452 self .assertEqual (resp .getcode (), 200 )
438453
0 commit comments