From 28aa5d34b0bf2417089bf49fd1573a620720997a Mon Sep 17 00:00:00 2001 From: Ollie Ford Date: Wed, 5 Sep 2018 10:43:39 +0100 Subject: [PATCH 1/2] Add failing test for #1809 --- tests/test_core/test_decorator_calls.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/test_core/test_decorator_calls.py b/tests/test_core/test_decorator_calls.py index 9e3638cc2..5d2f6a4ef 100644 --- a/tests/test_core/test_decorator_calls.py +++ b/tests/test_core/test_decorator_calls.py @@ -85,3 +85,14 @@ class TesterWithSetup(unittest.TestCase): def test_still_the_same(self): bucket = self.conn.get_bucket('mybucket') bucket.name.should.equal("mybucket") + + +@mock_s3_deprecated +class TesterWithStaticmethod(object): + + @staticmethod + def static(*args): + assert not args or not isinstance(args[0], TesterWithStaticmethod) + + def test_no_instance_sent_to_staticmethod(self): + self.static() From 0ac989cfd4a0e684df2f0170821d1598526484bf Mon Sep 17 00:00:00 2001 From: Ollie Ford Date: Wed, 5 Sep 2018 10:39:09 +0100 Subject: [PATCH 2/2] Fix #1809: skip patching staticmethods --- moto/core/models.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/moto/core/models.py b/moto/core/models.py index 92dc2a980..adc06a9c0 100644 --- a/moto/core/models.py +++ b/moto/core/models.py @@ -89,6 +89,17 @@ class BaseMockAWS(object): if inspect.ismethod(attr_value) and attr_value.__self__ is klass: continue + # Check if this is a staticmethod. If so, skip patching + for cls in inspect.getmro(klass): + if attr_value.__name__ not in cls.__dict__: + continue + bound_attr_value = cls.__dict__[attr_value.__name__] + if not isinstance(bound_attr_value, staticmethod): + break + else: + # It is a staticmethod, skip patching + continue + try: setattr(klass, attr, self(attr_value, reset=False)) except TypeError: