pytest-dev / pytest-dev/pytest-django
Client: testing exceptions in views (client.store_exc_info)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Django client.py section linked in the issue, especially client.store_exc_info, and review how pytest-django currently documents testing views that raise exceptions. Determine whether the result should be a documentation clarification or a pytest-django helper, then document or test the agreed approach so the exception-handling behavior is clear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- testing
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100