summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Golden <mail@timgolden.me.uk>2018-07-26 21:05:00 (GMT)
committerGitHub <noreply@github.com>2018-07-26 21:05:00 (GMT)
commit6a62e1d365934de82ff7c634981b3fbf218b4d5f (patch)
tree71310dcc25bc62aa6791b991294b2e483724ebb3 /Lib
parent56b29b6d6fa3eb32bb1533ee3f21b1e7135648a0 (diff)
downloadcpython-6a62e1d365934de82ff7c634981b3fbf218b4d5f.zip
cpython-6a62e1d365934de82ff7c634981b3fbf218b4d5f.tar.gz
cpython-6a62e1d365934de82ff7c634981b3fbf218b4d5f.tar.bz2
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
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_bz2.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index 003497f..e62729a 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -6,6 +6,7 @@ from io import BytesIO, DEFAULT_BUFFER_SIZE
import os
import pickle
import glob
+import tempfile
import pathlib
import random
import shutil
@@ -76,11 +77,14 @@ class BaseTest(unittest.TestCase):
BIG_DATA = bz2.compress(BIG_TEXT, compresslevel=1)
def setUp(self):
- self.filename = support.TESTFN
+ fd, self.filename = tempfile.mkstemp()
+ os.close(fd)
def tearDown(self):
- if os.path.isfile(self.filename):
+ try:
os.unlink(self.filename)
+ except FileNotFoundError:
+ pass
class BZ2FileTest(BaseTest):