summaryrefslogtreecommitdiff
path: root/fixtures/tests
diff options
context:
space:
mode:
authorStephen Finucane <stephenfin@redhat.com>2021-02-25 11:37:42 +0000
committerStephen Finucane <stephenfin@redhat.com>2021-02-25 11:40:43 +0000
commitfe830674abd4926d96d38f9992f3e31b00cd891a (patch)
tree36fb7bc3822d2a4019151410cb2a317bf1f890ac /fixtures/tests
parentf8df2192bf1190ff21a3067bb9e132b6db85191e (diff)
downloadfixtures-git-fe830674abd4926d96d38f9992f3e31b00cd891a.tar.gz
Fix tests on Python 3.9
I'm not entirely sure this is correct, but it's the only thing I can find related to changes in classmethod in Python 3.9. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Diffstat (limited to 'fixtures/tests')
-rw-r--r--fixtures/tests/_fixtures/test_monkeypatch.py48
1 files changed, 35 insertions, 13 deletions
diff --git a/fixtures/tests/_fixtures/test_monkeypatch.py b/fixtures/tests/_fixtures/test_monkeypatch.py
index 6f11fab..746f6dd 100644
--- a/fixtures/tests/_fixtures/test_monkeypatch.py
+++ b/fixtures/tests/_fixtures/test_monkeypatch.py
@@ -14,6 +14,7 @@
# limitations under that license.
import functools
+import sys
import testtools
from testtools.matchers import Is
@@ -32,7 +33,7 @@ class C(object):
class D(object):
def bar(self): pass
- def bar_two_args(self, arg):
+ def bar_two_args(self, arg=None):
return (self, arg)
@classmethod
def bar_cls(cls):
@@ -188,14 +189,27 @@ class TestMonkeyPatch(testtools.TestCase, TestWithFixtures):
'fixtures.tests._fixtures.test_monkeypatch.C.foo_cls',
D.bar_cls_args)
with fixture:
- cls, target_class = C.foo_cls()
- self.expectThat(cls, Is(D))
- self.expectThat(target_class, Is(C))
- cls, target_class = C().foo_cls()
- self.expectThat(cls, Is(D))
- self.expectThat(target_class, Is(C))
- self._check_restored_static_or_class_method(oldmethod, oldmethod_inst,
- C, 'foo_cls')
+ # Python 3.9 changes the behavior of the classmethod decorator so
+ # that it now honours the descriptor binding protocol [1].
+ # This means we're now going to call the monkeypatched classmethod
+ # the way we would have if it hadn't been monkeypatched: simply
+ # with the class
+ #
+ # https://bugs.python.org/issue19072
+ if sys.version_info >= (3, 9):
+ cls, = C.foo_cls()
+ self.expectThat(cls, Is(D))
+ cls, = C().foo_cls()
+ self.expectThat(cls, Is(D))
+ else:
+ cls, target_class = C.foo_cls()
+ self.expectThat(cls, Is(D))
+ self.expectThat(target_class, Is(C))
+ cls, target_class = C().foo_cls()
+ self.expectThat(cls, Is(D))
+ self.expectThat(target_class, Is(C))
+ self._check_restored_static_or_class_method(
+ oldmethod, oldmethod_inst, C, 'foo_cls')
def test_patch_classmethod_with_function(self):
oldmethod = C.foo_cls
@@ -222,12 +236,20 @@ class TestMonkeyPatch(testtools.TestCase, TestWithFixtures):
with fixture:
slf, cls = C.foo_cls()
self.expectThat(slf, Is(d))
- self.expectThat(cls, Is(C))
+ # See note in test_patch_classmethod_with_classmethod on changes in
+ # Python 3.9
+ if sys.version_info >= (3, 9):
+ self.expectThat(cls, Is(None))
+ else:
+ self.expectThat(cls, Is(C))
slf, cls = C().foo_cls()
self.expectThat(slf, Is(d))
- self.expectThat(cls, Is(C))
- self._check_restored_static_or_class_method(oldmethod, oldmethod_inst,
- C, 'foo_cls')
+ if sys.version_info >= (3, 9):
+ self.expectThat(cls, Is(None))
+ else:
+ self.expectThat(cls, Is(C))
+ self._check_restored_static_or_class_method(
+ oldmethod, oldmethod_inst, C, 'foo_cls')
def test_patch_function_with_staticmethod(self):
oldmethod = fake_no_args