          user and/or token.
          """
          self.handler._force_user = user
          self.handler._force_token = token
          if user is None:
              self.logout()  # Also clear any possible session info if required
  
      def request(self, **kwargs):
          # Ensure that any credentials set get added to every request.
          kwargs.update(self._credentials)
 
</s> remove         # Force authenticating as `None` should also logout the user session.
        self.client.force_authenticate(None)
 </s> add         # Force authenticating with `None` user and token should also logout
        # the user session.
        self.client.force_authenticate(user=None, token=None) </s> remove     return Response({
        'auth': request.META.get('HTTP_AUTHORIZATION', b''),
        'user': request.user.username
    })
 </s> add     data = {'auth': request.META.get('HTTP_AUTHORIZATION', b'')}
    if request.user:
        data['user'] = request.user.username
    if request.auth:
        data['token'] = request.auth.key
    return Response(data) </s> remove         self.client.force_authenticate(user)
 </s> add         self.client.force_authenticate(user=user)
        response = self.client.get('/view/')

        assert response.data['user'] == 'example'
        assert 'token' not in response.data

    def test_force_authenticate_with_token(self):
        """
        Setting `.force_authenticate()` with a token forcibly authenticates each
        request with that token.
        """
        user = User.objects.create_user('example', 'example@example.com')
        token = Token.objects.create(key='xyz', user=user)

        self.client.force_authenticate(token=token) </s> remove         Setting `.force_authenticate()` forcibly authenticates each request.
 </s> add         Setting `.force_authenticate()` with a user forcibly authenticates each
        request with that user.
        if user is None and token is None:
          user and/or token.
          """
          self.handler._force_user = user
          self.handler._force_token = token
        if user is None and token is None:
              self.logout()  # Also clear any possible session info if required
  
      def request(self, **kwargs):
          # Ensure that any credentials set get added to every request.
          kwargs.update(self._credentials)
keep keep keep keep replace keep keep keep keep keep
 Make `APIClient.force_authenticate()` work with `user=None` (#8212)

* Fix testing with token

* Add unit test

* Split unit test into 3

* Fix linting error 
rest_framework/test.py