tests: switch to tempfile.TemporaryDirectory
Now that we don't need to support Python 2, we can switch to this
API for better contextmanager logic.
Change-Id: I2d03e391121886547e7808a3b5c3b470c411533f
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/337515
Reviewed-by: LaMont Jones <lamontjones@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index ede4154..85c2073 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -17,7 +17,6 @@
import os
import platform
import re
-import shutil
import tempfile
import unittest
import xml.dom.minidom
@@ -92,7 +91,8 @@
"""TestCase for parsing manifests."""
def setUp(self):
- self.tempdir = tempfile.mkdtemp(prefix='repo_tests')
+ self.tempdirobj = tempfile.TemporaryDirectory(prefix='repo_tests')
+ self.tempdir = self.tempdirobj.name
self.repodir = os.path.join(self.tempdir, '.repo')
self.manifest_dir = os.path.join(self.repodir, 'manifests')
self.manifest_file = os.path.join(
@@ -111,7 +111,7 @@
""")
def tearDown(self):
- shutil.rmtree(self.tempdir, ignore_errors=True)
+ self.tempdirobj.cleanup()
def getXmlManifest(self, data):
"""Helper to initialize a manifest for testing."""