aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_importlib/source/test_finder.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-05-08 17:49:09 +0300
committerGitHub <noreply@github.com>2022-05-08 17:49:09 +0300
commit086c6b1b0fe8d47ebd15512d7bdcb64c60a360f0 (patch)
treea7b1eaf75879c3fded1b946b2331f6a45dfc8fc7 /Lib/test/test_importlib/source/test_finder.py
parent8f293180791f2836570bdfc29aadba04a538d435 (diff)
downloadcpython-086c6b1b0fe8d47ebd15512d7bdcb64c60a360f0.tar.gz
cpython-086c6b1b0fe8d47ebd15512d7bdcb64c60a360f0.zip
bpo-45046: Support context managers in unittest (GH-28045)
Add methods enterContext() and enterClassContext() in TestCase. Add method enterAsyncContext() in IsolatedAsyncioTestCase. Add function enterModuleContext().
Diffstat (limited to 'Lib/test/test_importlib/source/test_finder.py')
-rw-r--r--Lib/test/test_importlib/source/test_finder.py19
1 files changed, 5 insertions, 14 deletions
diff --git a/Lib/test/test_importlib/source/test_finder.py b/Lib/test/test_importlib/source/test_finder.py
index 6a23e9d50f6..bed9d56dca8 100644
--- a/Lib/test/test_importlib/source/test_finder.py
+++ b/Lib/test/test_importlib/source/test_finder.py
@@ -157,21 +157,12 @@ class FinderTests(abc.FinderTests):
def test_no_read_directory(self):
# Issue #16730
tempdir = tempfile.TemporaryDirectory()
+ self.enterContext(tempdir)
+ # Since we muck with the permissions, we want to set them back to
+ # their original values to make sure the directory can be properly
+ # cleaned up.
original_mode = os.stat(tempdir.name).st_mode
- def cleanup(tempdir):
- """Cleanup function for the temporary directory.
-
- Since we muck with the permissions, we want to set them back to
- their original values to make sure the directory can be properly
- cleaned up.
-
- """
- os.chmod(tempdir.name, original_mode)
- # If this is not explicitly called then the __del__ method is used,
- # but since already mucking around might as well explicitly clean
- # up.
- tempdir.__exit__(None, None, None)
- self.addCleanup(cleanup, tempdir)
+ self.addCleanup(os.chmod, tempdir.name, original_mode)
os.chmod(tempdir.name, stat.S_IWUSR | stat.S_IXUSR)
finder = self.get_finder(tempdir.name)
found = self._find(finder, 'doesnotexist')