My understanding from reading the docs runs something like this:
- client is a subclass of TestCase. When we run
manage.py test, an instance of our SimpleTest class (which inherits from TestCase) is created for each method that starts ‘test_’. This isself. - Client is a subclass of client. We can create new Client instances and sometimes it’s helpful to do so.
- Yet somehow, when we type
self.client, what we are referring to is a particular Client that was instantiated when the TestCase was created, and not the client class one layer below TestCase.
Is this correct? If so, how is this the case – something to do with Superclasses?
If i’m understanding both your question and the documentation correctly. The
clientproperty is provided as a convenience it makes sense that each test has access to afrom django.test.client import ClientClient instance.Your first question:
from the source It doesn’t look like Client is a subclass of TestCase at all.
From the source I don’t see where? the Client class is being instantiated and attached to TestCase instance but it is somewhere.
Django is completely open source so given some free time it is easy to track down how things and where things are happening. https://github.com/django/django Following the import paths and grepping around can find all answers