Code

Opened 8 years ago

Closed 7 years ago

#2734 closed defect (duplicate)

Test framework doesn't install _(), maybe?

Reported by: dave AT avaragado.org Owned by: adrian
Component: Testing framework Version: master
Severity: normal Keywords:
Cc: mir@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The call to render_to_response includes the i18n magic _ function, but it hasn't been imported. Result: grief, in conjunction with the new test client at least (it gives me a 500 response).

To fix: import _ from the usual place. I trust a patch submission for this change is not required :-)

Attachments (0)

Change History (3)

comment:1 Changed 8 years ago by adrian

  • Summary changed from django.contrib.auth.views.logout uses _ without importing to Test framework doesn't install _(), maybe?

The _ function isn't meant to be imported, as django.utils.translation.trans_real.install automatically puts it in the global namespace. I suspect this is a problem with the testing framework, then...

comment:2 Changed 8 years ago by mir@…

  • Cc mir@… added

I had exactly this problem with my own test stuff, and the problem turned out to be a little bit nasty. I use py.test together with doctests. During doctests, _ will be overwritten with each evaluated value, as happens during interactive use.

I solved it by doing

__builtins__['_'] = gettext

after each doctest. You can't use the '_' of i18n in doctests, but this never a problem for me.

Perhaps this can be done in the new django test framework, too.

comment:3 Changed 7 years ago by Michael Radziej <mir@…>

  • Component changed from Contrib apps to Unit test system
  • Resolution set to duplicate
  • Status changed from new to closed

duplicate of #2920

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.