Skip to content

Commit

Permalink
Disallow twill 3.2
Browse files Browse the repository at this point in the history
twill 3.2 replaced `requests` with `httpx`, and `httpx` has a default
timeout of 5 s on a request, while `requests` didn't enforce a timeout by
default.

It is not currently easy to configure a timeout for twill, this is a
possible workaround:

```
from httpx import Timeout

twill.commands.browser._client._timeout = Timeout(None)
```

Fix errors like the following in ToolShed tests, where resetting
repository metadata takes longer than 5 s:

```
self = <tool_shed.test.functional.test_0000_basic_repository_features.TestBasicRepositoryFeatures object at 0x7f28f99197c0>

    def test_0090_verify_repository_metadata(self):
        """Verify that resetting the metadata does not change it."""
        repository = self._get_repository_by_name_and_owner(repository_name, common.test_user_1_name)
>       self.verify_unchanged_repository_metadata(repository)

lib/tool_shed/test/functional/test_0000_basic_repository_features.py:264:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
lib/tool_shed/test/base/twilltestcase.py:2073: in verify_unchanged_repository_metadata
    self.reset_repository_metadata(repository)
lib/tool_shed/test/base/twilltestcase.py:1774: in reset_repository_metadata
    self.visit_url("/repository/reset_all_metadata", params=params)
lib/tool_shed/test/base/twilltestcase.py:845: in visit_url
    return self._browser.visit_url(url, allowed_codes=allowed_codes)
lib/tool_shed/test/base/twillbrowser.py:35: in visit_url
    return visit_url(url, allowed_codes=allowed_codes)
lib/tool_shed/test/base/twillbrowser.py:20: in visit_url
    new_url = tc.go(url)
.venv/lib/python3.8/site-packages/twill/commands.py:120: in go
    browser.go(url)
.venv/lib/python3.8/site-packages/twill/browser.py:192: in go
    self._journey("open", try_url)
.venv/lib/python3.8/site-packages/twill/browser.py:677: in _journey
    result = self._client.get(url)
.venv/lib/python3.8/site-packages/httpx/_client.py:1041: in get
    return self.request(
.venv/lib/python3.8/site-packages/httpx/_client.py:814: in request
    return self.send(request, auth=auth, follow_redirects=follow_redirects)
.venv/lib/python3.8/site-packages/httpx/_client.py:901: in send
    response = self._send_handling_auth(
.venv/lib/python3.8/site-packages/httpx/_client.py:929: in _send_handling_auth
    response = self._send_handling_redirects(
.venv/lib/python3.8/site-packages/httpx/_client.py:966: in _send_handling_redirects
    response = self._send_single_request(request)
.venv/lib/python3.8/site-packages/httpx/_client.py:1002: in _send_single_request
    response = transport.handle_request(request)
.venv/lib/python3.8/site-packages/httpx/_transports/default.py:228: in handle_request
    resp = self._pool.handle_request(req)
/opt/hostedtoolcache/Python/3.8.18/x64/lib/python3.8/contextlib.py:131: in __exit__
    self.gen.throw(type, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    @contextlib.contextmanager
    def map_httpcore_exceptions() -> typing.Iterator[None]:
        try:
            yield
        except Exception as exc:
            mapped_exc = None

            for from_exc, to_exc in HTTPCORE_EXC_MAP.items():
                if not isinstance(exc, from_exc):
                    continue
                # We want to map to the most specific exception we can find.
                # Eg if `exc` is an `httpcore.ReadTimeout`, we want to map to
                # `httpx.ReadTimeout`, not just `httpx.TimeoutException`.
                if mapped_exc is None or issubclass(to_exc, mapped_exc):
                    mapped_exc = to_exc

            if mapped_exc is None:  # pragma: no cover
                raise

            message = str(exc)
>           raise mapped_exc(message) from exc
E           httpx.ReadTimeout: timed out

.venv/lib/python3.8/site-packages/httpx/_transports/default.py:83: ReadTimeout
```
  • Loading branch information
nsoranzo committed Nov 15, 2023
1 parent a89abf2 commit 623acb4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ sphinx-rtd-theme = ">=1.0.0,<2" # https://github.com/python-poetry/poetry/issue
statsd = "*"
testfixtures = "*"
tuspy = "*"
twill = "*"
twill = "!=3.2" # httpx client timeout not configurable
watchdog = "*"

[tool.poetry.group.typecheck.dependencies]
Expand Down

0 comments on commit 623acb4

Please sign in to comment.