twisted / treq

Python requests like API built on top of Twisted's HTTP client.
Other
585 stars 137 forks source link

Tests are broken due to Werkzeug ImportError #352

Closed twm closed 1 year ago

twm commented 1 year ago
 Traceback (most recent call last):
  File "/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/twisted/trial/runner.py", line 596, in loadPackage
    module = modinfo.load()
  File "/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/twisted/python/modules.py", line 389, in load
    return self.pathEntry.pythonPath.moduleLoader(self.name)
  File "/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/twisted/python/reflect.py", line 297, in namedAny
    topLevelPackage = _importAndCheckStack(trialname)
  File "/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/twisted/python/reflect.py", line 244, in _importAndCheckStack
    raise excValue.with_traceback(excTraceback)
  File "/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/treq/test/local_httpbin/test/test_child.py", line 28, in <module>
    from .. import child, shared
  File "/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/treq/test/local_httpbin/child.py", line 11, in <module>
    import httpbin
  File "/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/httpbin/__init__.py", line 3, in <module>
    from .core import *
  File "/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/httpbin/core.py", line 21, in <module>
    from werkzeug.wrappers import BaseResponse
builtins.ImportError: cannot import name 'BaseResponse' from 'werkzeug.wrappers' (/home/runner/work/treq/treq/.tox/py39-twisted_latest/lib/python3.9/site-packages/werkzeug/wrappers/__init__.py)
SamirPS commented 1 year ago

Hello,

It's because it's deprecated, https://github.com/pallets/werkzeug/issues/2360#issuecomment-1081009270

Quick fix : Werkzeug==2.0.3

twm commented 1 year ago

@SamirPS Thanks, that is more specific than the pin I was using!

Ultimately, it's because httpbin is unmaintained since 2018. :disappointed: I'll fix this by pinning for the moment and file another ticket to address the larger issue.

SamirPS commented 1 year ago

No problem, You can't use another library ?

twm commented 1 year ago

@SamirPS Is there another implementation of httpbin? We ended up here because our integration test suite used to hit httpbin.org, but of course this required internet access and was flaky. Right now the tests run httpbin in a subprocess.

There's some value in having integration tests that do real I/O, but IMO some of what we are testing this way would be better done using in-memory techniques like treq.testing.

Maybe we end up reimplementing the bits of httpbin we need in Twisted?

SamirPS commented 1 year ago

Maybe try this

https://github.com/postmanlabs/httpbin/issues/673#issuecomment-1150816886

arnimarj commented 1 year ago

I've been doing this in my tests:

    import werkzeug.wrappers
    Response = werkzeug.wrappers.Response
    werkzeug.wrappers.BaseResponse = Response  # type: ignore[attr-defined]

...and doing it before I import httpbin (I've been running httpbin under WSGIResource with some hacks).

EDIT: I'm running httpbin in process, not as a separate process like the treq tests are apparently doing

SamirPS commented 1 year ago

Where the werkzeug is localized the source code?

twm commented 1 year ago

@SamirPS It's not — Werkzeug is used by httpbin, not treq.