8000 bpo-34239: Convert test_bz2 to use tempfile (#8485) · python/cpython@6a62e1d · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a62e1d

Browse files
authored
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
1 parent 56b29b6 commit 6a62e1d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Lib/test/test_bz2.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import pickle
88
import glob
9+
import tempfile
910
import pathlib
1011
import random
1112
import shutil
@@ -76,11 +77,14 @@ class BaseTest(unittest.TestCase):
7677
BIG_DATA = bz2.compress(BIG_TEXT, compresslevel=1)
7778

7879
def setUp(self):
79-
self.filename = support.TESTFN
80+
fd, self.filename = tempfile.mkstemp()
81+
os.close(fd)
8082

8183
def tearDown(self):
82-
if os.path.isfile(self.filename):
84+
try:
8385
os.unlink(self.filename)
86+
except FileNotFoundError:
87+
pass
8488

8589

8690
class BZ2FileTest(BaseTest):

0 commit comments

Comments
 (0)
0