summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_mailbox.py
diff options
context:
space:
mode:
authorVinay Sajip <vinay_sajip@yahoo.co.uk>2012-03-02 01:01:13 (GMT)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>2012-03-02 01:01:13 (GMT)
commitf959618142888fab373c43edd35f20506a9740dc (patch)
treecc1f5a1bf7bac40e8b2913bb4c60522d875c4d22 /Lib/test/test_mailbox.py
parent4d2bfb5e08619581a9f205b6145f97e4b0d838df (diff)
downloadcpython-f959618142888fab373c43edd35f20506a9740dc.zip
cpython-f959618142888fab373c43edd35f20506a9740dc.tar.gz
cpython-f959618142888fab373c43edd35f20506a9740dc.tar.bz2
Closes #14158: improved resilience to test files left behind.
Diffstat (limited to 'Lib/test/test_mailbox.py')
-rw-r--r--Lib/test/test_mailbox.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index ef64366..e09aea4 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -7,6 +7,7 @@ import email
import email.message
import re
import io
+import shutil
import tempfile
from test import support
import unittest
@@ -38,12 +39,7 @@ class TestBase(unittest.TestCase):
def _delete_recursively(self, target):
# Delete a file or delete a directory recursively
if os.path.isdir(target):
- for path, dirs, files in os.walk(target, topdown=False):
- for name in files:
- os.remove(os.path.join(path, name))
- for name in dirs:
- os.rmdir(os.path.join(path, name))
- os.rmdir(target)
+ shutil.rmtree(target)
elif os.path.exists(target):
os.remove(target)
@@ -2029,6 +2025,10 @@ class MaildirTestCase(unittest.TestCase):
def setUp(self):
# create a new maildir mailbox to work with:
self._dir = support.TESTFN
+ if os.path.isdir(self._dir):
+ shutil.rmtree(self._dir)
+ elif os.path.isfile(self._dir):
+ os.unlink(self._dir)
os.mkdir(self._dir)
os.mkdir(os.path.join(self._dir, "cur"))
os.mkdir(os.path.join(self._dir, "tmp"))