diff options
| author | Natalia <124304+nessita@users.noreply.github.com> | 2023-12-15 13:50:05 -0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2023-12-27 06:05:33 +0100 |
| commit | 7c26dbf6ef9415f873ae43f12e6ab3742857c898 (patch) | |
| tree | 26950e50b3d2f592e8101488f9e464d31b9029df /tests/cache | |
| parent | 2a2481f5a2179ac11947d92a097c9042bb57e17c (diff) | |
Improved cache.tests.FileBasedCacheTests.test_touch to avoid flakiness due to slow file system access.
Diffstat (limited to 'tests/cache')
| -rw-r--r-- | tests/cache/tests.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py index fcce9579d4..c2a1ebdbb8 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -1766,6 +1766,28 @@ class FileBasedCacheTests(BaseCacheTests, TestCase): self.assertIs(cache.has_key("key"), False) mocked_open.assert_called_once() + def test_touch(self): + """Override to manually advance time since file access can be slow.""" + + class ManualTickingTime: + def __init__(self): + # Freeze time, calling `sleep` will manually advance it. + self._time = time.time() + + def time(self): + return self._time + + def sleep(self, seconds): + self._time += seconds + + mocked_time = ManualTickingTime() + with ( + mock.patch("django.core.cache.backends.filebased.time", new=mocked_time), + mock.patch("django.core.cache.backends.base.time", new=mocked_time), + mock.patch("cache.tests.time", new=mocked_time), + ): + super().test_touch() + @unittest.skipUnless(RedisCache_params, "Redis backend not configured") @override_settings( |
