vcrpy icon indicating copy to clipboard operation
vcrpy copied to clipboard

AttributeError: module 'tornado' has no attribute 'curl_httpclient'

Open manuel14 opened this issue 4 years ago • 2 comments
trafficstars

1

I am seeing this error pop up many times, seems to be only failing when using python3. I have discovered that nose-detecthttp uses vcrpy under the hood. So that is one way that the import error comes up. We are using this versions of tornado, vcrpy and nose-detecthttp are:

Package Version


nose-detect-leaky-state 0.0.7 nose-detecthttp 1.2.1 tornado 4.5 tornado-cors 0.6.0
vcrpy 4.0.2
viivakoodi 0.8.0 wcwidth 0.2.4 websocket-client 0.58.0 Werkzeug 0.15.0 wheel 0.34.2 wrapt 1.10.10 XML2Dict 0.2.2 xmltodict 0.12.0 yamllint 1.19.0 yarl 1.3.0 zipp 0.6.0 This is the stack trace of the error

item = <TestCaseFunction test_twilio_exception_is_not_reraised_if_twilio_raises_403_exception>

   @pytest.hookimpl(hookwrapper=True)
   

   def pytest_runtest_call(item):
   

   enabled = item.config._detecthttp_enabled
   

   if enabled:
   

   cassette_name = "%s.yaml" % item
   

   cassette_manager = vcr.use_cassette(
   

   cassette_name,
   

   serializer='yaml',
   

   record_mode='once',
   

   ignore_localhost=True,

This is not the only way that the error comes up, i have other tests that fail. The weird thing is that it comes up in tests that do not use cassetes even.

manuel14 avatar Apr 23 '21 20:04 manuel14

I also get this error and the tests that fail aren't consistent. This error will cause a test failure in one build, but will fail a totally different test in another build. It feels completely random and very frustrating.

My logs are pointing to this part of patch.py and it looks like vcr is wrapping an import with a try block. It seems like the try block isn't broad enough to catch all potential issues.

self = <vcr.patch.CassettePatcherBuilder object at 0x7f9bfb7cdeb8>

    @_build_patchers_from_mock_triples_decorator
    def _tornado(self):
        try:
            import tornado.simple_httpclient as simple
        except ImportError:  # pragma: no cover
            pass
        else:
            from .stubs.tornado_stubs import vcr_fetch_impl

            new_fetch_impl = vcr_fetch_impl(self._cassette, _SimpleAsyncHTTPClient_fetch_impl)
            yield simple.SimpleAsyncHTTPClient, "fetch_impl", new_fetch_impl
        try:
>           import tornado.curl_httpclient as curl
E           AttributeError: module 'tornado' has no attribute 'curl_httpclient'

.venv/lib/python3.6/site-packages/vcr/patch.py:305: AttributeError

chingc avatar Jun 09 '21 22:06 chingc

Would a simple except (AttributeError, ImportError) work? 🤔

lesmo avatar Aug 18 '21 16:08 lesmo