Explicitly reset format caches during testing

This seems to be necessary primarily for consistency when running tests in
parallel.

Fixes #483
This commit is contained in:
Christopher C. Wells 2023-02-11 20:21:09 -08:00
parent 1d9577a192
commit a5504520d1
1 changed files with 3 additions and 1 deletions

View File

@ -4,7 +4,7 @@ from django.core.management import call_command
from django.test import TestCase from django.test import TestCase
from django.test import Client as HttpClient from django.test import Client as HttpClient
from django.utils import timezone from django.utils import timezone
from django.utils.formats import get_format from django.utils.formats import get_format, reset_format_cache
from faker import Faker from faker import Faker
@ -38,12 +38,14 @@ class FormsTestCaseBase(TestCase):
@staticmethod @staticmethod
def localdate_string(datetime=None): def localdate_string(datetime=None):
"""Converts an object to a local date string for form input.""" """Converts an object to a local date string for form input."""
reset_format_cache()
date_format = get_format("DATE_INPUT_FORMATS")[0] date_format = get_format("DATE_INPUT_FORMATS")[0]
return timezone.localdate(datetime).strftime(date_format) return timezone.localdate(datetime).strftime(date_format)
@staticmethod @staticmethod
def localtime_string(datetime=None): def localtime_string(datetime=None):
"""Converts an object to a local time string for form input.""" """Converts an object to a local time string for form input."""
reset_format_cache()
datetime_format = get_format("DATETIME_INPUT_FORMATS")[0] datetime_format = get_format("DATETIME_INPUT_FORMATS")[0]
return timezone.localtime(datetime).strftime(datetime_format) return timezone.localtime(datetime).strftime(datetime_format)