[Answered ]-Testing 500 error code in django rest API unit test

1👍

The APIClient class supports the same request interface as Django’s standard Client class so it is possible to use raise_request_exception argument to control whether to raise exceptions or return a 500 response (set raise_request_exception to False for a 500 response).

Changing the setUp() method should do the trick:

def setUp(self):
    self.client = APIClient(raise_request_exception=False)

Here is the documentation and ticket discussing this issue for more info.

Leave a comment