Opened 7 years ago

Closed 7 years ago

Last modified 4 years ago

#7487 closed (invalid)

Test Client's Response lacks context/template when using Doctests

Reported by: DanielLindsley Owned by: jacob
Component: Testing framework Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When using 'django.test.client.Client' in conjunction with doctests, the response that comes back from the client will be without the 'context' or 'template' variables. This occurs because the 'template_rendered' signal doesn't seem to fire. The doctest code I am using is:

>>> from django.test import Client
>>> c = Client()

>>> r = c.get('/weather/')
>>> r.status_code

>>> r.context[-1]['station'].id

Without the attached patch, 'r.context' is set to None (via an else case - 'setattr(response, detail, None)' in the Client's request method).

The context/template variables are never set because the 'template_rendered' signal doesn't fire as it has not been imported, thus failing to be connected. This only occurs when using doctests; unittests seem to act differently and aren't affected by this. The attached diff works with both doctests & unittests.

This is not a duplicate of ticket #3051, as these tests are being run from both ' test' as well as ' shell'.

Attachments (1)

doctest_client_fix.diff (474 bytes) - added by DanielLindsley 7 years ago.
Patch For Client

Download all attachments as: .zip

Change History (5)

Changed 7 years ago by DanielLindsley

Patch For Client

comment:1 Changed 7 years ago by DanielLindsley

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Correction: as these tests are being run from ' test', not ' shell'.

comment:2 Changed 7 years ago by jacob

  • milestone changed from 1.0 alpha to 1.0
  • Owner changed from nobody to jacob
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 7 years ago by DanielLindsley

  • Resolution set to invalid
  • Status changed from assigned to closed

Can't recreate with the original code or a simple test case. Closing.

comment:4 Changed 4 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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