Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failures with Python 3.12.0b1:AttributeError: type object 'VCRHTTPConnection[…]' has no attribute 'debuglevel' #707

Closed
mgorny opened this issue May 29, 2023 · 4 comments

Comments

@mgorny
Copy link
Contributor

mgorny commented May 29, 2023

When running the test suite against Python 3.12.0b1, I get a lot of failures from integration tests, they seem to roughly boil down to the same thing:

_____________ ERROR at setup of test_matchers[uri-http://httpbin.org/get?p1=q1&p2=q2-http://httpbin.org/get?p2=q2&p1=q1] ______________

tmpdir = local('/tmp/pytest-of-mgorny/pytest-3/test_matchers_uri_http___httpb0')
httpbin = <pytest_httpbin.serve.Server object at 0x7f39ca56e5d0>
httpbin_secure = <pytest_httpbin.serve.SecureServer object at 0x7f39c9c6d520>

    @pytest.fixture
    def cassette(tmpdir, httpbin, httpbin_secure):
        """
        Helper fixture used to prepare the cassette
        returns path to the recorded cassette
        """
        default_uri = _replace_httpbin(DEFAULT_URI, httpbin, httpbin_secure)
    
        cassette_path = str(tmpdir.join("test.yml"))
        with vcr.use_cassette(cassette_path, record_mode=vcr.mode.ALL):
>           urlopen(default_uri)

tests/integration/test_matchers.py:24: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.12/urllib/request.py:212: in urlopen
    _opener = opener = build_opener()
/usr/lib/python3.12/urllib/request.py:593: in build_opener
    opener.add_handler(klass())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <urllib.request.HTTPHandler object at 0x7f39c9c6d7f0>, debuglevel = None

    def __init__(self, debuglevel=None):
>       self._debuglevel = debuglevel if debuglevel is not None else http.client.HTTPConnection.debuglevel
E       AttributeError: type object 'VCRHTTPConnection/tmp/pytest-of-mgorny/pytest-3/test_matchers_uri_http___httpb0/test.yml' has no attribute 'debuglevel'. Did you mean: 'set_debuglevel'?

/usr/lib/python3.12/urllib/request.py:1255: AttributeError

I'm guessing that __getattr__() doesn't work here (because stuff's being called from a "type object"?).

Full log: py312.log

@mgorny
Copy link
Contributor Author

mgorny commented May 29, 2023

The following cheap hack seems to resolve it:

diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py
index 54ce470..3e0b21b 100644
--- a/vcr/stubs/__init__.py
+++ b/vcr/stubs/__init__.py
@@ -171,6 +171,8 @@ class VCRHTTPResponse(HTTPResponse):
 class VCRConnection:
     # A reference to the cassette that's currently being patched in
     cassette = None
+    debuglevel = HTTPSConnection.debuglevel
+    _http_vsn = HTTPSConnection._http_vsn
 
     def _port_postfix(self):
         """

However, there is probably a better way of resolving this.

@mgorny
Copy link
Contributor Author

mgorny commented Jul 31, 2023

Gentle ping.

@jairhenrique
Copy link
Collaborator

@mgorny can you help us by submitting a PR with python 3.12 support in CI?

@mgorny
Copy link
Contributor Author

mgorny commented Aug 2, 2023

@mgorny can you help us by submitting a PR with python 3.12 support in CI?

Sure, done that in #754. That said, that tox.ini is true horror.

mgorny added a commit to mgorny/vcrpy that referenced this issue Aug 3, 2023
Copy the `debuglevel` and `_http_vsn` attributes from base connection
class into response classes, in order to fix compatibility with
Python 3.12.  For reasons I don't comprehend, these end up being called
on the class rather than instance, so regular proxying logic does not
work.

Fixes kevin1024#707
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants