﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4530	doctests don't play well with i18n: they override the value of _ builtin	marcin@…	Adrian Holovaty	"Doctests are being run in Python's interactive mode, which means -- among other things -- that any expresion returning a value other than None will overwrite the value of the _ builtin.  This causes problems if you are trying to test views that use _().

Running the doctests from the attached tests.py file results in an exception:

{{{
======================================================================
FAIL: Doctest: doctestproject.doctestapp.tests
----------------------------------------------------------------------
Traceback (most recent call last):
  File ""/home/marcink/checkout/django/django/test/_doctest.py"", line 2170, in runTest
    raise self.failureException(self.format_failure(new.getvalue()))
AssertionError: Failed doctest test for doctestproject.doctestapp.tests
  File ""/home/marcink/tmp/doctestproject/doctestapp/tests.py"", line 0, in tests

----------------------------------------------------------------------
File ""/home/marcink/tmp/doctestproject/doctestapp/tests.py"", line 9, in doctestproject.doctestapp.tests
Failed example:
    _('Test marked for translation')
Exception raised:
    Traceback (most recent call last):
      File ""/home/marcink/checkout/django/django/test/_doctest.py"", line 1249, in __run
        compileflags, 1) in test.globs
      File ""<doctest doctestproject.doctestapp.tests[1]>"", line 1, in ?
        _('Test marked for translation')
    TypeError: 'str' object is not callable
----------------------------------------------------------------------
File ""/home/marcink/tmp/doctestproject/doctestapp/tests.py"", line 16, in doctestproject.doctestapp.tests
Failed example:
    ((_ == first_time_gettext) or (_ == gettext))
Expected:
    True
Got:
    False


----------------------------------------------------------------------
Ran 2 tests in 0.014s

FAILED (failures=1)
}}}

The attached patch solves the problem at the expense of incompatibility with the standard doctest behavior.  I imagine some people do write doctests that depend on the _ variable, but the use of gettext's _() is so common in Django apps that a slight rewrite of those doctests will be easier than rewriting internationalized apps.
"		closed	Testing framework	dev		duplicate	doctests,gettext,translation		Unreviewed	1	0	0	0	0	0
