From 037994f9835cafe248e8a78e4cb875f01116f1ef Mon Sep 17 00:00:00 2001 From: Valerii Ponomarov Date: Fri, 22 Nov 2019 01:24:13 +0530 Subject: [py2to3] Add method to the base class for proper calling of it's methods Lots of test classes are wrapped by the 'runs_on' decorator. This decorator replaces original test class with it's copy where parent class is original test class if we use py3. Such situation leads to the impossibility to use following approach in py3: super(SomeClass, some_class_instance).some_method() And, the above approach is py2/3 compatible approach for calling parent class's methods. The problem we face is that we fall into the unexpected recursion here. So, add 'get_super_method' to the base class, which detects such situation and returns proper method of a proper parent class. Also, fix test class located at 'glusterd/test_peer_status.py' module to have proof of concept. With this change 'test_peer_probe_status' test case becomes completely py2/3 compatible. Example of new method usage: @runs_on([['distributed'], ['glusterfs']]) class TestDecoratedClass(GlusterBaseClass): ... def setUp(self): self.get_super_method(self, 'setUp')() ... This approach must be used instead of existing calls of 'im_func' function if we want to support both at once - python2 and python3. Signed-off-by: Valerii Ponomarov Change-Id: I23f4462b64f9d4dd90812273f08fb756d073ab76 --- tests/functional/glusterd/test_peer_status.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests/functional/glusterd') diff --git a/tests/functional/glusterd/test_peer_status.py b/tests/functional/glusterd/test_peer_status.py index cc282de57..65e8db9ed 100644 --- a/tests/functional/glusterd/test_peer_status.py +++ b/tests/functional/glusterd/test_peer_status.py @@ -34,8 +34,7 @@ from glustolibs.gluster.peer_ops import (peer_probe, peer_status, peer_detach, class TestPeerStatus(GlusterBaseClass): def setUp(self): - - GlusterBaseClass.setUp.im_func(self) + self.get_super_method(self, 'setUp')() # Performing peer detach ret = peer_detach_servers(self.mnode, self.servers) @@ -67,7 +66,7 @@ class TestPeerStatus(GlusterBaseClass): "servers %s" % self.servers) g.log.info("Peer probe success for detached " "servers %s", self.servers) - GlusterBaseClass.tearDown.im_func(self) + self.get_super_method(self, 'tearDown')() def test_peer_probe_status(self): -- cgit