Unverified Kaydet (Commit) 6a62e1d3 authored tarafından Tim Golden's avatar Tim Golden Kaydeden (comit) GitHub

bpo-34239: Convert test_bz2 to use tempfile (#8485)

* bpo-34239: Convert test_bz2 to use tempfile

test_bz2 currently uses the test.support.TESTFN functionality which creates a temporary file local to the test directory named around the pid.

This can give rise to race conditions where tests are competing with each other to delete and recreate the file.

This change converts the tests to use tempfile.mkstemp which gives a different file every time from the system's temp area
üst 56b29b6d
...@@ -6,6 +6,7 @@ from io import BytesIO, DEFAULT_BUFFER_SIZE ...@@ -6,6 +6,7 @@ from io import BytesIO, DEFAULT_BUFFER_SIZE
import os import os
import pickle import pickle
import glob import glob
import tempfile
import pathlib import pathlib
import random import random
import shutil import shutil
...@@ -76,11 +77,14 @@ class BaseTest(unittest.TestCase): ...@@ -76,11 +77,14 @@ class BaseTest(unittest.TestCase):
BIG_DATA = bz2.compress(BIG_TEXT, compresslevel=1) BIG_DATA = bz2.compress(BIG_TEXT, compresslevel=1)
def setUp(self): def setUp(self):
self.filename = support.TESTFN fd, self.filename = tempfile.mkstemp()
os.close(fd)
def tearDown(self): def tearDown(self):
if os.path.isfile(self.filename): try:
os.unlink(self.filename) os.unlink(self.filename)
except FileNotFoundError:
pass
class BZ2FileTest(BaseTest): class BZ2FileTest(BaseTest):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment