Re: [Django] #35986: Test classes with @translation.override decorator are not run

25 views
Skip to first unread message

Django

unread,
Dec 9, 2024, 5:56:33 AM12/9/24
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
----------------------------------+------------------------------------
Reporter: Arthur Pemberton | Owner: (none)
Type: Bug | Status: new
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Arthur Pemberton):

I believe this bug is covering the existence of another bug: that
`TIME_INPUT_FORMATS` is not used by `forms.TimeField` as one might expect
-- and that in fact, `CustomTimeInputFormatsTests`, which tests this,
should be failing.

Should I wait on this ticket before creating one about
`TIME_INPUT_FORMATS` not working as expected? Or should I create another
ticket in parallel?
--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 9, 2024, 7:51:47 AM12/9/24
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
----------------------------------+------------------------------------
Reporter: Arthur Pemberton | Owner: (none)
Type: Bug | Status: new
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Jacob Walls):

I think separate tickets make sense.
--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:4>

Django

unread,
Dec 14, 2024, 3:19:44 AM12/14/24
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
----------------------------------+------------------------------------
Reporter: Arthur Pemberton | Owner: (none)
Type: Bug | Status: new
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Simon Charette):

Tests appears to pass even with the `timezone.override` adjustments

{{{#!diff
diff --git a/tests/forms_tests/tests/test_input_formats.py
b/tests/forms_tests/tests/test_input_formats.py
index c5023d8d10..30ca53ba4b 100644
--- a/tests/forms_tests/tests/test_input_formats.py
+++ b/tests/forms_tests/tests/test_input_formats.py
@@ -118,9 +118,13 @@ def test_localized_timeField_with_inputformat(self):
self.assertEqual(text, "13:30:00")


-...@translation.override(None)
@override_settings(TIME_INPUT_FORMATS=["%I:%M:%S %p", "%I:%M %p"])
class CustomTimeInputFormatsTests(SimpleTestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.enterClassContext(translation.override(None))
+ super().setUpClass()
+
def test_timeField(self):
"TimeFields can parse dates in the default format"
f = forms.TimeField()
@@ -431,9 +435,13 @@ def test_localized_dateField_with_inputformat(self):
self.assertEqual(text, "21.12.2010")


-...@translation.override(None)
@override_settings(DATE_INPUT_FORMATS=["%d.%m.%Y", "%d-%m-%Y"])
class CustomDateInputFormatsTests(SimpleTestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.enterClassContext(translation.override(None))
+ super().setUpClass()
+
def test_dateField(self):
"DateFields can parse dates in the default format"
f = forms.DateField()
@@ -752,9 +760,13 @@ def
test_localized_dateTimeField_with_inputformat(self):
self.assertEqual(text, "21.12.2010 13:30:00")


-...@translation.override(None)
@override_settings(DATETIME_INPUT_FORMATS=["%I:%M:%S %p %d/%m/%Y", "%I:%M
%p %d-%m-%Y"])
class CustomDateTimeInputFormatsTests(SimpleTestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.enterClassContext(translation.override(None))
+ super().setUpClass()
+
def test_dateTimeField(self):
"DateTimeFields can parse dates in the default format"
f = forms.DateTimeField()
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py
index c45f078ef6..c66c9a9c75 100644
--- a/tests/timezones/tests.py
+++ b/tests/timezones/tests.py
@@ -921,9 +921,13 @@ def test_aware_datetime_in_other_timezone(self):
self.assertEqual(obj.dt, dt)


-...@translation.override(None)
@override_settings(DATETIME_FORMAT="c", TIME_ZONE="Africa/Nairobi",
USE_TZ=True)
class TemplateTests(SimpleTestCase):
+ @classmethod
+ def setUpClass(cls):
+ cls.enterClassContext(translation.override(None))
+ super().setUpClass()
+
@requires_tz_support
def test_localtime_templatetag_and_filters(self):
"""
@@ -1324,7 +1328,6 @@ def test_localized_model_form(self):
self.assertIn("2011-09-01 17:20:30", str(form))


-...@translation.override(None)
@override_settings(
DATETIME_FORMAT="c",
TIME_ZONE="Africa/Nairobi",
@@ -1334,6 +1337,7 @@ def test_localized_model_form(self):
class AdminTests(TestCase):
@classmethod
def setUpTestData(cls):
+ cls.enterClassContext(translation.override(None))
cls.u1 = User.objects.create_user(
password="secret",
last_login=datetime.datetime(2007, 5, 30, 13, 20, 10,
tzinfo=UTC),
@@ -1403,3 +1407,4 @@ def test_change_readonly_in_other_timezone(self):
reverse("admin_tz:timezones_timestamp_change",
args=(t.pk,))
)
self.assertContains(response,
t.created.astimezone(ICT).isoformat())
+ self.assertContains(response,
t.created.astimezone(ICT).isoformat())
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:5>

Django

unread,
Dec 14, 2024, 9:44:16 AM12/14/24
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
----------------------------------+------------------------------------
Reporter: Arthur Pemberton | Owner: (none)
Type: Bug | Status: new
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Jacob Walls):

For reference, this is the companion ticket that was closed: ticket:35990.
--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:6>

Django

unread,
Dec 14, 2024, 5:41:50 PM12/14/24
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
----------------------------------+------------------------------------
Reporter: Arthur Pemberton | Owner: (none)
Type: Bug | Status: new
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Arthur Pemberton):

Correct. This seems to work as such by design.
--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:7>

Django

unread,
Apr 1, 2025, 9:54:31 AM4/1/25
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
----------------------------------+------------------------------------
Reporter: Arthur Pemberton | Owner: (none)
Type: Bug | Status: new
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Adya):

Is there someone already working on it?

If not, could you kindly assign it to me?
--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:8>

Django

unread,
Apr 8, 2025, 2:37:21 AM4/8/25
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
----------------------------------+----------------------------------------
Reporter: Arthur Pemberton | Owner: Ahmed Nassar
Type: Bug | Status: assigned
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Ahmed Nassar):

* owner: (none) => Ahmed Nassar
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:9>

Django

unread,
Apr 8, 2025, 3:50:23 AM4/8/25
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
----------------------------------+----------------------------------------
Reporter: Arthur Pemberton | Owner: Ahmed Nassar
Type: Bug | Status: assigned
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+----------------------------------------
Changes (by Ahmed Nassar):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:10>

Django

unread,
Apr 8, 2025, 4:49:58 AM4/8/25
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
-------------------------------------+-------------------------------------
Reporter: Arthur Pemberton | Owner: Ahmed
| Nassar
Type: Bug | Status: assigned
Component: Utilities | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:11>

Django

unread,
Apr 9, 2025, 3:49:29 AM4/9/25
to django-...@googlegroups.com
#35986: Test classes with @translation.override decorator are not run
-------------------------------------+-------------------------------------
Reporter: Arthur Pemberton | Owner: Ahmed
| Nassar
Type: Bug | Status: closed
Component: Utilities | Version: 5.1
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"522dd021b2738d15723448808606491063ff2e70" 522dd021]:
{{{#!CommitTicketReference repository=""
revision="522dd021b2738d15723448808606491063ff2e70"
Fixed #35986 -- Fixed test classes with @translation.override decorator.

Co-authored-by: Simon Charette <chare...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35986#comment:12>
Reply all
Reply to author
Forward
0 new messages