From 44e923662205f2a2413fadb23715dc2934bff625 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Tue, 3 Sep 2024 14:30:51 +1000 Subject: [PATCH 1/3] Only call super() during MockHttp if required With pytest 8.2 and above, any class that contains classes is collected, which means they are instantiated, which MockHttp's superclasses do not accept, since they require keyword arguments. To work around this, only call the superclass's __init__ method if we are passed kwargs. --- libcloud/test/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libcloud/test/__init__.py b/libcloud/test/__init__.py index d45c82c84d..1cc595f685 100644 --- a/libcloud/test/__init__.py +++ b/libcloud/test/__init__.py @@ -87,7 +87,7 @@ def read(self, chunk_size=None): return StringIO.read(self) -class MockHttp(LibcloudConnection): +class MockHttp(LibcloudConnection, unittest.TestCase): """ A mock HTTP client/server suitable for testing purposes. This replaces `HTTPConnection` by implementing its API and returning a mock response. @@ -108,7 +108,11 @@ def __init__(self, *args, **kwargs): # within a response if isinstance(self, unittest.TestCase): unittest.TestCase.__init__(self, "__init__") - super().__init__(*args, **kwargs) + # When this class is collected, it is instantiated with no arguments, + # which breaks any superclasses that expect arguments, so only + # do so if we were passed any keyword arguments. + if kwargs: + super().__init__(*args, **kwargs) def _get_request(self, method, url, body=None, headers=None): # Find a method we can use for this request From 30c21cd936e789f9a7e41feed74714bd9bb440dd Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sun, 2 Mar 2025 18:10:11 +0100 Subject: [PATCH 2/3] Use latest version of pytest and pytest plugins. --- requirements-tests.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/requirements-tests.txt b/requirements-tests.txt index a1efcf8b2c..fb76114f9c 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -1,10 +1,10 @@ coverage[toml]==7.2.7; python_version >= '3.8' requests>=2.31.0 requests_mock==1.11.0 -pytest==8.1.1 -pytest-xdist==3.5.0 -pytest-timeout==2.2.0 -pytest-benchmark[histogram]==4.0.0 +pytest==8.3.5 +pytest-xdist==3.6.1 +pytest-timeout==2.3.1 +pytest-benchmark[histogram]==5.1.0 cryptography==44.0.2 # NOTE: Only needed by nttcis loadbalancer driver From 36b5dff063cb4902ae496bc6d0c92db4215f53ce Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sun, 2 Mar 2025 18:10:54 +0100 Subject: [PATCH 3/3] Add changelog entry for #2033. --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 968b2b3703..acb9a16421 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -135,6 +135,11 @@ Other / Development (#1994) [Tomaz Muraus - @Kami] +- Add a workaround so tests work with pytest >= 8.2. Also use latest version of + pytest for running tests. + (#2033) + [Steve Kowalik - @s-t-e-v-e-n-k] + Changes in Apache Libcloud 3.8.0 --------------------------------