treq
treq copied to clipboard
Tests are broken due to Werkzeug ImportError
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)
Hello,
It's because it's deprecated, https://github.com/pallets/werkzeug/issues/2360#issuecomment-1081009270
Quick fix : Werkzeug==2.0.3
@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.
No problem, You can't use another library ?
@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?
Maybe try this
https://github.com/postmanlabs/httpbin/issues/673#issuecomment-1150816886
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
Where the werkzeug is localized the source code?
@SamirPS It's not — Werkzeug is used by httpbin, not treq.