Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#8358 closed (fixed)

Test client raises UnboundLocalError when view raises exception and 500.html does not exist.

Reported by: ryan_freckleton Owned by: nobody
Component: Testing framework Version: master
Severity: Keywords: test client exception unboundlocalerror
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If an exception is raised in a view that is requested by the test client and the 500.html template does not exist, the test fails with the following traceback:

Traceback (most recent call last):
  File "/home/ryan/src/django_stuff/client_test/../client_test/test_app/tests.py", line 5, in test
    response = self.client.get('/')
  File "/home/ryan/src/django_stuff/django_py/lib/python2.5/site-packages/django/test/client.py", line 265, in get
    return self.request(**r)
  File "/home/ryan/src/django_stuff/django_py/lib/python2.5/site-packages/django/test/client.py", line 231, in request
    response.client = self
UnboundLocalError: local variable 'response' referenced before assignment

The view function used to generate this was:

def raise_error(request):
    raise Exception()

self.exc_info in the client is not set, so no exception is raised at line client.py:225-228, and an UnboundLocalError is raised at line 231.

This could possibly be related to issue #8136, but I'm not really sure.

Change History (6)

comment:1 Changed 7 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This could be the same cause as #8136, but the reported exception is slightly different; I'll make sure when I get around to fixing the problem.

comment:2 Changed 7 years ago by russellm

  • Component changed from Core framework to Unit test system

comment:3 Changed 7 years ago by ryan_freckleton

I tried the patch associated with #8136 and it seems to fix this error message as well. So it's probably the same root cause.

comment:4 Changed 7 years ago by russellm

  • Resolution set to duplicate
  • Status changed from new to closed

On deeper inspection, this is the same problem as #8136.

comment:5 Changed 6 years ago by jacob

  • Resolution changed from duplicate to fixed

(In [10371]) Fixed a whole bunch of small docs typos, errors, and ommissions.

Fixes #8358, #8396, #8724, #9043, #9128, #9247, #9267, #9267, #9375, #9409, #9414, #9416, #9446, #9454, #9464, #9503, #9518, #9533, #9657, #9658, #9683, #9733, #9771, #9835, #9836, #9837, #9897, #9906, #9912, #9945, #9986, #9992, #10055, #10084, #10091, #10145, #10245, #10257, #10309, #10358, #10359, #10424, #10426, #10508, #10531, #10551, #10635, #10637, #10656, #10658, #10690, #10699, #19528.

Thanks to all the respective authors of those tickets.

comment:18 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top