Opened 9 days ago
Last modified 4 days ago
#35986 new Bug
Test classes with @translation.override decorator are not run
Reported by: | Arthur Pemberton | Owned by: | |
---|---|---|---|
Component: | Utilities | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
For example, the test "CustomTimeInputFormatsTests" does not get discovered and ran via:
./runtests.py forms_tests.tests.test_input_formats
And attempting to run the test direct with ./runtests.py forms_tests.tests.test_input_formats.CustomTimeInputFormatsTests
results in an error:
AttributeError: 'CustomTimeInputFormatsTests' object has no attribute 'runTest'. Did you mean: 'subTest'?
Using Python 3.12, I followed the steps from https://docs.djangoproject.com/en/dev/internals/contributing/writing-code/unit-tests/#running-the-unit-tests to setup a clean environment.
Attachments (1)
Change History (8)
by , 9 days ago
Attachment: | test_input_formats-output.txt added |
---|
comment:1 by , 9 days ago
comment:2 by , 9 days ago
Component: | Uncategorized → Utilities |
---|---|
Summary: | Some unit tests in forms_tests.tests.test_input_formats not running → Test classes with @translation.override decorator are not run |
Triage Stage: | Unreviewed → Accepted |
Thank you - well spotted!
Looks like any test class with a class level @translation.override
is affected (this includes tests.timezones.tests.TemplateTests
and tests.timezones.tests.AdminTests
)
comment:3 by , 9 days ago
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?
comment:5 by , 4 days ago
Tests appears to pass even with the timezone.override
adjustments
-
tests/forms_tests/tests/test_input_formats.py
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 b def test_localized_timeField_with_inputformat(self): 118 118 self.assertEqual(text, "13:30:00") 119 119 120 120 121 @translation.override(None)122 121 @override_settings(TIME_INPUT_FORMATS=["%I:%M:%S %p", "%I:%M %p"]) 123 122 class CustomTimeInputFormatsTests(SimpleTestCase): 123 @classmethod 124 def setUpClass(cls): 125 cls.enterClassContext(translation.override(None)) 126 super().setUpClass() 127 124 128 def test_timeField(self): 125 129 "TimeFields can parse dates in the default format" 126 130 f = forms.TimeField() … … def test_localized_dateField_with_inputformat(self): 431 435 self.assertEqual(text, "21.12.2010") 432 436 433 437 434 @translation.override(None)435 438 @override_settings(DATE_INPUT_FORMATS=["%d.%m.%Y", "%d-%m-%Y"]) 436 439 class CustomDateInputFormatsTests(SimpleTestCase): 440 @classmethod 441 def setUpClass(cls): 442 cls.enterClassContext(translation.override(None)) 443 super().setUpClass() 444 437 445 def test_dateField(self): 438 446 "DateFields can parse dates in the default format" 439 447 f = forms.DateField() … … def test_localized_dateTimeField_with_inputformat(self): 752 760 self.assertEqual(text, "21.12.2010 13:30:00") 753 761 754 762 755 @translation.override(None)756 763 @override_settings(DATETIME_INPUT_FORMATS=["%I:%M:%S %p %d/%m/%Y", "%I:%M %p %d-%m-%Y"]) 757 764 class CustomDateTimeInputFormatsTests(SimpleTestCase): 765 @classmethod 766 def setUpClass(cls): 767 cls.enterClassContext(translation.override(None)) 768 super().setUpClass() 769 758 770 def test_dateTimeField(self): 759 771 "DateTimeFields can parse dates in the default format" 760 772 f = forms.DateTimeField() -
tests/timezones/tests.py
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py index c45f078ef6..c66c9a9c75 100644
a b def test_aware_datetime_in_other_timezone(self): 921 921 self.assertEqual(obj.dt, dt) 922 922 923 923 924 @translation.override(None)925 924 @override_settings(DATETIME_FORMAT="c", TIME_ZONE="Africa/Nairobi", USE_TZ=True) 926 925 class TemplateTests(SimpleTestCase): 926 @classmethod 927 def setUpClass(cls): 928 cls.enterClassContext(translation.override(None)) 929 super().setUpClass() 930 927 931 @requires_tz_support 928 932 def test_localtime_templatetag_and_filters(self): 929 933 """ … … def test_localized_model_form(self): 1324 1328 self.assertIn("2011-09-01 17:20:30", str(form)) 1325 1329 1326 1330 1327 @translation.override(None)1328 1331 @override_settings( 1329 1332 DATETIME_FORMAT="c", 1330 1333 TIME_ZONE="Africa/Nairobi", … … def test_localized_model_form(self): 1334 1337 class AdminTests(TestCase): 1335 1338 @classmethod 1336 1339 def setUpTestData(cls): 1340 cls.enterClassContext(translation.override(None)) 1337 1341 cls.u1 = User.objects.create_user( 1338 1342 password="secret", 1339 1343 last_login=datetime.datetime(2007, 5, 30, 13, 20, 10, tzinfo=UTC), … … def test_change_readonly_in_other_timezone(self): 1403 1407 reverse("admin_tz:timezones_timestamp_change", args=(t.pk,)) 1404 1408 ) 1405 1409 self.assertContains(response, t.created.astimezone(ICT).isoformat()) 1410 self.assertContains(response, t.created.astimezone(ICT).isoformat())
comment:6 by , 4 days ago
For reference, this is the companion ticket that was closed: ticket:35990.
From that module, the following tests are seemingly all affected: