I think the problem may be in the context of the_manager or with statement.
async def __async_send_recieve(self, jdata): async with self.aws: await self.aws.send(json.dumps(jdata)) return await self.aws.receive()
When you call "c", the context should be reproduced as follows (with better exception handling and all the benefits of context managers, so you can present the __async_send_recieve stream as:
self.aws.__aenter__() self.aws.send(data) self.aws.receive() self.aws.__aexit__()
To prove this theory, add a print statement to the __aenter__ and __aexit__ , and you can better visualize the context manager flow.
The correction will consist of re-authorization in each request. But I assume that you want your test class to control the context used to communicate with the remote server. (my asynchronous syntax may be a little wrong here, but conceptually with context managers):
class Mtest(): def __init__(self, ...): ... def __enter__(self,): self.authorize() def __exit__(self): self.deauthorize() async def make_async_request(self, data): await self.aws.send(json.dumps(data)) return await self.aws.receive() with Mtest(api_key) as m: m.make_async_request({'test_data': 'dummy_test_data'}) m.make_async_request({'more_data': 'more_mock_data'})
source share