From 04b1dad6d83678339bb69f0daa773d95bd4022b6 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 4 May 2023 00:11:11 +0200 Subject: [PATCH] Removed `test_cron_execution_upon_system_clock_change`. The test is too brittle as it depends on small mocked clock skews and it can easily fail. --- tests/test_cron.py | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/tests/test_cron.py b/tests/test_cron.py index 5bc41e636..0b983ff79 100644 --- a/tests/test_cron.py +++ b/tests/test_cron.py @@ -1,23 +1,11 @@ -import datetime import queue import pytest import time -from dateutil.tz import gettz -from mock import patch - test_timeout = 10 cron_queue = queue.Queue() -class MockDatetime(datetime.datetime): - timedelta = datetime.timedelta() - - @classmethod - def now(cls): - return super().now(tz=gettz()) + cls.timedelta - - def _test_cron_queue(expected_msg: str): msg = None test_start = time.time() @@ -37,27 +25,6 @@ def test_cron_execution(): _test_cron_queue('cron_test') -def test_cron_execution_upon_system_clock_change(): - """ - Test that the cronjob runs at the right time even upon DST or other - system clock changes. - """ - # Mock datetime.datetime with a class that has overridable timedelta - patcher = patch('datetime.datetime', MockDatetime) - - try: - patcher.start() - time.sleep(1) - # Simulate a +1hr shift on the system clock - MockDatetime.timedelta = datetime.timedelta(hours=1) - time.sleep(1) - finally: - patcher.stop() - - # Ensure that the cronjob that was supposed to run in an hour is now running - _test_cron_queue('cron_1hr_test') - - if __name__ == '__main__': pytest.main()