Skip to content

Client: testing exceptions in views (client.store_exc_info) #130

Open
@blueyed

Description

@blueyed

I want to test a view that throws an exception, and came up with the following code to make it work, so that the exception is not re-thrown by the client (code ref: https://github.com/django/django/blob/master/django/test/client.py#L421-443):

def test_foo(client):
    def store_exc_info(*args, **kwargs):
        pass
    # client.store_exc_info = lambda *args, **kwargs: True
    client.store_exc_info = store_exc_info

    client.get('/raises-500')

Given that it was not trivial to figure this out I wonder if this is the correct approach and if pytest-django could help in this regard (documentation, helper, ...)

I will look into providing a documentation update for Django itself, but want to get some feedback first.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions