Skip to content

Commit 28ce07a

Browse files
authored
bpo-31066: Fix test_httpservers.test_last_modified() (#2933)
Write the temporary file on disk and then get its modification time.
1 parent cc42c12 commit 28ce07a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Lib/test/test_httpservers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,11 @@ def setUp(self):
335335
self.tempdir = tempfile.mkdtemp(dir=basetempdir)
336336
self.tempdir_name = os.path.basename(self.tempdir)
337337
self.base_url = '/' + self.tempdir_name
338-
with open(os.path.join(self.tempdir, 'test'), 'wb') as temp:
338+
tempname = os.path.join(self.tempdir, 'test')
339+
with open(tempname, 'wb') as temp:
339340
temp.write(self.data)
340-
mtime = os.fstat(temp.fileno()).st_mtime
341+
temp.flush()
342+
mtime = os.stat(tempname).st_mtime
341343
# compute last modification datetime for browser cache tests
342344
last_modif = datetime.datetime.fromtimestamp(mtime,
343345
datetime.timezone.utc)
@@ -471,7 +473,7 @@ def test_browser_cache(self):
471473
headers['If-Modified-Since'] = email.utils.format_datetime(new_dt,
472474
usegmt=True)
473475
response = self.request(self.base_url + '/test', headers=headers)
474-
self.check_status_and_reason(response, HTTPStatus.NOT_MODIFIED)
476+
self.check_status_and_reason(response, HTTPStatus.NOT_MODIFIED)
475477

476478
def test_browser_cache_file_changed(self):
477479
# with If-Modified-Since earlier than Last-Modified, must return 200
@@ -491,7 +493,7 @@ def test_browser_cache_with_If_None_Match_header(self):
491493
headers['If-Modified-Since'] = self.last_modif_header
492494
headers['If-None-Match'] = "*"
493495
response = self.request(self.base_url + '/test', headers=headers)
494-
self.check_status_and_reason(response, HTTPStatus.OK)
496+
self.check_status_and_reason(response, HTTPStatus.OK)
495497

496498
def test_invalid_requests(self):
497499
response = self.request('/', method='FOO')

0 commit comments

Comments
 (0)