11import requests
22import os
33
4- from time import sleep
4+ from time import mktime
5+ from datetime import datetime
56
67from astropy .config import paths
78
@@ -146,7 +147,7 @@ def test_login():
146147 assert not mytest .authenticated () # Should not be accessing cache
147148
148149
149- def test_timeout ():
150+ def test_timeout (monkeypatch ):
150151 cache_conf .reset ()
151152
152153 mytest = CacheTestClass ()
@@ -155,21 +156,23 @@ def test_timeout():
155156 mytest .clear_cache ()
156157 assert len (os .listdir (mytest .cache_location )) == 0
157158
158- cache_conf .cache_timeout = 2 # Set to 2 sec so we can reach timeout easily
159-
160159 set_response (TEXT1 ) # setting the response
161160
162161 resp = mytest .test_func (URL1 ) # should be cached
163162 assert resp .content == TEXT1
164163
165- set_response (TEXT2 ) # changing the respont
164+ set_response (TEXT2 ) # changing the response
166165
167166 resp = mytest .test_func (URL1 ) # should access cached value
168167 assert resp .content == TEXT1
169168
170- sleep (2 ) # run out cache time
169+ # Changing the file date so the cache will consider it expired
170+ cache_file = list (mytest .cache_location .iterdir ())[0 ]
171+ modTime = mktime (datetime (1970 , 1 , 1 ).timetuple ())
172+ os .utime (cache_file , (modTime , modTime ))
173+
171174 resp = mytest .test_func (URL1 )
172- assert resp .content == TEXT2 # no see the new response
175+ assert resp .content == TEXT2 # now see the new response
173176
174177
175178def test_deactivate ():
0 commit comments