Added __aenter__ method, returning the instance of AsyncHTMLSession within an asynchronous context.
Added __aexit__ method, ensuring proper closing of the session upon context exit.
Created a new test suite (test_async_context_manager) to validate the functionality of the async context manager.
Added test case to the test suite to ensure that the session can successfully make an HTTP GET request within the async context.
Description
This merge request introduces the addition of __aenter__ and __aexit__ methods to the AsyncHTMLSession class, providing support for using the class as an asynchronous context manager. Additionally, a test suite has been created to verify the functionality of the async context manager. Also, some imports have been moved to better align with PEP 8 – style guide.
Motivation
The introduction of the __aenter__ and __aexit__ methods allows users of the AsyncHTMLSession class to easily manage the lifecycle of the session within an asynchronous context. The __aenter__ method returns the instance itself, enabling seamless integration with asynchronous context management. On the other hand, the __aexit__ method ensures that the session is properly closed when exiting the context.
Test Results
The new test suite (test_async_context_manager) has been executed successfully, validating the behavior of the async context manager. The test case confirms that the AsyncHTMLSession instance can be used within an asynchronous context to make an HTTP GET request, and the session is properly closed upon exiting the context.
Changes Overview
__aenter__
method, returning the instance ofAsyncHTMLSession
within an asynchronous context.__aexit__
method, ensuring proper closing of the session upon context exit.test_async_context_manager
) to validate the functionality of the async context manager.Description
This merge request introduces the addition of
__aenter__
and__aexit__
methods to theAsyncHTMLSession
class, providing support for using the class as an asynchronous context manager. Additionally, a test suite has been created to verify the functionality of the async context manager. Also, some imports have been moved to better align with PEP 8 – style guide.Motivation
The introduction of the
__aenter__
and__aexit__
methods allows users of theAsyncHTMLSession
class to easily manage the lifecycle of the session within an asynchronous context. The__aenter__
method returns the instance itself, enabling seamless integration with asynchronous context management. On the other hand, the__aexit__
method ensures that the session is properly closed when exiting the context.Test Results
The new test suite (
test_async_context_manager
) has been executed successfully, validating the behavior of the async context manager. The test case confirms that theAsyncHTMLSession
instance can be used within an asynchronous context to make an HTTP GET request, and the session is properly closed upon exiting the context.