@pytest.mark.skipif(
    rest_framework.__version__.split(".")[0] >= "3",
    reason="DRF 3+ no longer calls model.clean",
)
def test_django_non_field_validation_error(rf, monkeypatch):
    def clean(self):
        raise ValidationError("I'm not taking any new people today")

    monkeypatch.setattr(models.Person, 'clean', clean)
    data = dump_json({"people": {"name": "Jason Api"}})

    request = rf.post(
        reverse("person-list"), data=data,
        content_type="application/vnd.api+json")
    view = PersonViewSet.as_view({'post': 'create'})
    response = view(request)
    response.render()

    assert response.status_code == 400, response.content
    assert not models.Person.objects.exists()

    results = {
        "errors": [{
            "status": "400",
            "path": "/-",
            "detail": "I'm not taking any new people today"
        }]
    }
    assert response.content == dump_json(results)
Django uses __all__ as the key for non-field errors
dataset/ETHPy150Open kevin-brown/drf-json-api/tests/test_errors.py/test_django_non_field_validation_error