https://github.com/python/cpython/commit/85d90b59e2a9185cad608c5047357be645b4d5c6
commit: 85d90b59e2a9185cad608c5047357be645b4d5c6
branch: main
author: Jason R. Coombs <[email protected]>
committer: jaraco <[email protected]>
date: 2024-06-20T19:00:39Z
summary:

gh-120801: Refactor importlib.metadata fixtures. (#120803)

These changes released with importlib_metadata 7.2.0.

files:
A Misc/NEWS.d/next/Tests/2024-06-20-12-51-26.gh-issue-120801.lMVXC9.rst
M Lib/test/test_importlib/metadata/fixtures.py
M Lib/test/test_importlib/metadata/test_api.py
M Lib/test/test_importlib/metadata/test_main.py

diff --git a/Lib/test/test_importlib/metadata/fixtures.py 
b/Lib/test/test_importlib/metadata/fixtures.py
index 7ff94c9afe88e1..81ff678f2864fb 100644
--- a/Lib/test/test_importlib/metadata/fixtures.py
+++ b/Lib/test/test_importlib/metadata/fixtures.py
@@ -1,10 +1,8 @@
-import os
 import sys
 import copy
 import json
 import shutil
 import pathlib
-import tempfile
 import textwrap
 import functools
 import contextlib
@@ -27,29 +25,12 @@
 
 
 @contextlib.contextmanager
-def tempdir():
-    tmpdir = tempfile.mkdtemp()
-    try:
-        yield pathlib.Path(tmpdir)
-    finally:
-        shutil.rmtree(tmpdir)
-
-
[email protected]
-def save_cwd():
-    orig = os.getcwd()
-    try:
-        yield
-    finally:
-        os.chdir(orig)
-
-
[email protected]
-def tempdir_as_cwd():
-    with tempdir() as tmp:
-        with save_cwd():
-            os.chdir(str(tmp))
-            yield tmp
+def tmp_path():
+    """
+    Like os_helper.temp_dir, but yields a pathlib.Path.
+    """
+    with os_helper.temp_dir() as path:
+        yield pathlib.Path(path)
 
 
 @contextlib.contextmanager
@@ -70,7 +51,7 @@ def setUp(self):
 class SiteDir(Fixtures):
     def setUp(self):
         super().setUp()
-        self.site_dir = self.fixtures.enter_context(tempdir())
+        self.site_dir = self.fixtures.enter_context(tmp_path())
 
 
 class OnSysPath(Fixtures):
diff --git a/Lib/test/test_importlib/metadata/test_api.py 
b/Lib/test/test_importlib/metadata/test_api.py
index 33c6e85ee94753..7d267564f0f5b5 100644
--- a/Lib/test/test_importlib/metadata/test_api.py
+++ b/Lib/test/test_importlib/metadata/test_api.py
@@ -109,7 +109,7 @@ def test_entry_points_unique_packages_normalized(self):
         Entry points should only be exposed for the first package
         on sys.path with a given name (even when normalized).
         """
-        alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
+        alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path())
         self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
         alt_pkg = {
             "DistInfo_pkg-1.1.0.dist-info": {
diff --git a/Lib/test/test_importlib/metadata/test_main.py 
b/Lib/test/test_importlib/metadata/test_main.py
index c4accaeb9ba9ed..e4218076f8cb0e 100644
--- a/Lib/test/test_importlib/metadata/test_main.py
+++ b/Lib/test/test_importlib/metadata/test_main.py
@@ -138,7 +138,7 @@ def test_unique_distributions(self):
         fixtures.build_files(self.make_pkg('abc'), self.site_dir)
         before = list(_unique(distributions()))
 
-        alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
+        alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path())
         self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
         fixtures.build_files(self.make_pkg('ABC'), alt_site_dir)
         after = list(_unique(distributions()))
diff --git 
a/Misc/NEWS.d/next/Tests/2024-06-20-12-51-26.gh-issue-120801.lMVXC9.rst 
b/Misc/NEWS.d/next/Tests/2024-06-20-12-51-26.gh-issue-120801.lMVXC9.rst
new file mode 100644
index 00000000000000..8559cb8b99c384
--- /dev/null
+++ b/Misc/NEWS.d/next/Tests/2024-06-20-12-51-26.gh-issue-120801.lMVXC9.rst
@@ -0,0 +1,2 @@
+Cleaned up fixtures for importlib.metadata tests and consolidated behavior
+with 'test.support.os_helper'.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to