2323import aiohttp
2424import aiohttp .test_utils
2525import yarl
26+ from http_server_mock import HttpServerMock
2627from pkg_resources import iter_entry_points
2728
2829from opentelemetry import context
@@ -313,18 +314,26 @@ async def request_handler(request):
313314 def test_credential_removal (self ):
314315 trace_configs = [aiohttp_client .create_trace_config ()]
315316
316- url = "http://username:[email protected] /status/200" 317- with self .subTest (url = url ):
317+ app = HttpServerMock ("test_credential_removal" )
318318
319- async def do_request (url ):
320- async with aiohttp .ClientSession (
321- trace_configs = trace_configs ,
322- ) as session :
323- async with session .get (url ):
324- pass
319+ @app .route ("/status/200" )
320+ def index ():
321+ return "hello"
325322
326- loop = asyncio .get_event_loop ()
327- loop .run_until_complete (do_request (url ))
323+ url = "http://username:password@localhost:5000/status/200"
324+
325+ with app .run ("localhost" , 5000 ):
326+ with self .subTest (url = url ):
327+
328+ async def do_request (url ):
329+ async with aiohttp .ClientSession (
330+ trace_configs = trace_configs ,
331+ ) as session :
332+ async with session .get (url ):
333+ pass
334+
335+ loop = asyncio .get_event_loop ()
336+ loop .run_until_complete (do_request (url ))
328337
329338 self .assert_spans (
330339 [
@@ -333,7 +342,9 @@ async def do_request(url):
333342 (StatusCode .UNSET , None ),
334343 {
335344 SpanAttributes .HTTP_METHOD : "GET" ,
336- SpanAttributes .HTTP_URL : "http://httpbin.org/status/200" ,
345+ SpanAttributes .HTTP_URL : (
346+ "http://localhost:5000/status/200"
347+ ),
337348 SpanAttributes .HTTP_STATUS_CODE : int (HTTPStatus .OK ),
338349 },
339350 )
0 commit comments