Skip to content

Commit

Permalink
remember to open and close the requests session
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Sep 6, 2020
1 parent c923a96 commit e6fa6e6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion starlette/testclient.py
Expand Up @@ -455,11 +455,12 @@ def __enter__(self) -> requests.Session:
self.receive_queue = asyncio.Queue() # type: asyncio.Queue
self.task = loop.create_task(self.lifespan())
loop.run_until_complete(self.wait_startup())
return self
return super().__enter__()

def __exit__(self, *args: typing.Any) -> None:
loop = asyncio.get_event_loop()
loop.run_until_complete(self.wait_shutdown())
return super().__exit__(*args)

async def lifespan(self) -> None:
scope = {"type": "lifespan"}
Expand Down

0 comments on commit e6fa6e6

Please sign in to comment.