Skip to content

Commit

Permalink
Only call super() during MockHttp if required
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
s-t-e-v-e-n-k committed Sep 3, 2024
1 parent 1ebd605 commit 44e9236
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libcloud/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 44e9236

Please sign in to comment.