Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving #9141 #9395

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES/9141.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Modified the `ClientSession` class by adding a private attribute `_test` of type `bool`, with a default value of `False` to the class.
- Modified the default value of `retry_persistent_connection` in `ClientSession` to `False` if `_test` was `True`.
- Also, `TestClient` initialized `ClientSession` with `test=True`.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ Sergey Skripnick
Serhii Charykov
Serhii Kostel
Serhiy Storchaka
Shubh Agarwal
Simon Kennedy
Sin-Woo Bang
Stanislas Plum
Expand Down
6 changes: 5 additions & 1 deletion aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ def __init__(
max_line_size: int = 8190,
max_field_size: int = 8190,
fallback_charset_resolver: _CharsetResolver = lambda r, b: "utf-8",
test: bool = False,
) -> None:
# We initialise _connector to None immediately, as it's referenced in __del__()
# and could cause issues if an exception occurs during initialisation.
Expand Down Expand Up @@ -367,6 +368,7 @@ def __init__(

self._default_proxy = proxy
self._default_proxy_auth = proxy_auth
self._test = test

def __init_subclass__(cls: Type["ClientSession"]) -> None:
raise TypeError(
Expand Down Expand Up @@ -539,7 +541,9 @@ async def _request(
try:
with timer:
# https://www.rfc-editor.org/rfc/rfc9112.html#name-retrying-requests
retry_persistent_connection = method in IDEMPOTENT_METHODS
retry_persistent_connection = (
False if self._test else method in IDEMPOTENT_METHODS
)
while True:
url, auth_from_url = strip_auth_from_url(url)
if not url.raw_host:
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def __init__( # type: ignore[misc]
self._server = server
if cookie_jar is None:
cookie_jar = aiohttp.CookieJar(unsafe=True)
self._session = ClientSession(cookie_jar=cookie_jar, **kwargs)
self._session = ClientSession(cookie_jar=cookie_jar, test=True, **kwargs)
self._closed = False
self._responses: List[ClientResponse] = []
self._websockets: List[ClientWebSocketResponse] = []
Expand Down
Loading