This question is asked by many but almost all gave the same solution which I am already applying.
So I have classes TestCase
,B
,C
, D
& E
. Classes C
& D
inherit class B
& class E
inherits both C
& D
. Class B
inherits TestCase
.
When I run my code, class E
is only running with methods for class C
and ignoring D
all along. Now my classes go like these:
class GenericAuthClass(TestCase):
def setUp(self):
"""Create a dummy user for the purpose of testing."""
# set some objects and variabels
def _get_authenticated_api_client(self):
pass
class TokenAuthTests(GenericAuthClass):
def _get_authenticated_api_client(self):
"""Get token recieved on login."""
super()._get_authenticated_api_client()
# make object
return object
class BasicAuthTests(GenericAuthClass):
def _get_authenticated_api_client(self):
"""Get token recieved on login."""
super()._get_authenticated_api_client()
# make object
return object
class ClientTestCase(BasicAuthTests, TokenAuthTests):
def dothis(self):
return self._get_authenticated_api_client()
How can I call method (with same name) in C
and D
from E
like the diamond problem in C++
? As of now, when I call the certain method using self.method()
from E
it only calls that method from C
and ignores the same method from D
while I think it should call both methods.
Note that the method doesn't exist in class E
and my code is working right now without errors but only calling method from C
.
This seems like a Python question mainly but tagging Django too as TestCase
class might have something to do with it.