[Answered ]-Testing Django application cookies , sessions and states

2👍

The two statements do not contradict one another.

You can use self.client more than once during one test. You can log in, and the cookie handling in the test client will ‘remember’ your session, for subsequent requests.

Only when the test is done, is that state cleared.

You do not need to log out, because that’s a client state stored with cookies, and that state is cleared when the test is done. Only use .logout() if you wanted to test what happens after a user has logged in but their session has expired, or similar scenarios.

Leave a comment