From f9c73b2aee28fa970515951d6756bf5bc2f9ff77 Mon Sep 17 00:00:00 2001 From: Sebastien Robin <seb@nexedi.com> Date: Thu, 3 Nov 2016 14:50:22 +0100 Subject: [PATCH] fonctional tests: use UTC timezone to avoid failures in tests sensible to DST Some tests are sensible to Daylight saving time when they do some checking with non fixed dates --- product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py | 1 + product/ERP5Type/tests/ERP5TypeTestCase.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py b/product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py index 75f2c31180..c6c90bcfe6 100644 --- a/product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py +++ b/product/ERP5Type/tests/ERP5TypeFunctionalTestCase.py @@ -367,6 +367,7 @@ class ERP5TypeFunctionalTestCase(ERP5TypeTestCase): def afterSetUp(self): super(ERP5TypeFunctionalTestCase, self).afterSetUp() # create browser_id_manager + self.setTimeZoneToUTC() if not "browser_id_manager" in self.portal.objectIds(): self.portal.manage_addProduct['Sessions'].constructBrowserIdManager() self.commit() diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py index 863b764be8..040bdf5c32 100644 --- a/product/ERP5Type/tests/ERP5TypeTestCase.py +++ b/product/ERP5Type/tests/ERP5TypeTestCase.py @@ -288,6 +288,17 @@ class ERP5TypeTestCaseMixin(ProcessingNodeTestCase, PortalTestCase): assert date_time is None or isinstance(date_time, DateTime) _pinned_date_time = date_time + def setTimeZoneToUTC(self): + # Make sure tests runs with UTC timezone. Some tests are checking values + # based on now, and this could give unexpected results: + # DateTime("2016/10/31") - DateTime("2016/10/30") = 1.0416666666666667 if + # you are running on a timezone like Europe/Paris, while it return 1.0 for + # UTC + os.environ['TZ'] = "UTC" + time.tzset() + DateTime._isDST = False + DateTime._localzone = DateTime._localzone0 = DateTime._localzone1 = "UTC" + def unpinDateTime(self): self.pinDateTime(None) -- 2.30.9