treq icon indicating copy to clipboard operation
treq copied to clipboard

Tests are broken due to Werkzeug ImportError

Open twm opened this issue 2 years ago • 5 comments

 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)

twm avatar Aug 14 '22 00:08 twm

Hello,

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

Quick fix : Werkzeug==2.0.3

SamirPS avatar Aug 14 '22 01:08 SamirPS

@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.

twm avatar Aug 14 '22 01:08 twm

No problem, You can't use another library ?

SamirPS avatar Aug 14 '22 01:08 SamirPS

@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?

twm avatar Aug 14 '22 01:08 twm

Maybe try this

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

SamirPS avatar Aug 14 '22 01:08 SamirPS

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

arnimarj avatar Aug 15 '22 14:08 arnimarj

Where the werkzeug is localized the source code?

SamirPS avatar Aug 15 '22 14:08 SamirPS

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

twm avatar Aug 21 '22 20:08 twm