[Python-checkins] bpo-39950: Fix deprecation warning in test for `pathlib.Path.link_to()` (GH-26155)

gpshead webhook-mailer at python.org
Sun May 16 03:15:33 EDT 2021


https://github.com/python/cpython/commit/1a08c5ac49b748d5e4e4b508d22d3804e3cd4dcc
commit: 1a08c5ac49b748d5e4e4b508d22d3804e3cd4dcc
branch: main
author: Barney Gale <barney.gale at gmail.com>
committer: gpshead <greg at krypto.org>
date: 2021-05-16T00:15:25-07:00
summary:

bpo-39950: Fix deprecation warning in test for `pathlib.Path.link_to()` (GH-26155)

files:
M Lib/pathlib.py
M Lib/test/test_pathlib.py

diff --git a/Lib/pathlib.py b/Lib/pathlib.py
index 94e079fffef60..8e6eb48b9767c 100644
--- a/Lib/pathlib.py
+++ b/Lib/pathlib.py
@@ -1265,7 +1265,7 @@ def link_to(self, target):
         warnings.warn("pathlib.Path.link_to() is deprecated and is scheduled "
                       "for removal in Python 3.12. "
                       "Use pathlib.Path.hardlink_to() instead.",
-                      DeprecationWarning)
+                      DeprecationWarning, stacklevel=2)
         self._accessor.link(self, target)
 
     # Convenience functions for querying the stat results
diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py
index 6ed08f7e70ce3..55d63d539e550 100644
--- a/Lib/test/test_pathlib.py
+++ b/Lib/test/test_pathlib.py
@@ -1934,7 +1934,8 @@ def test_link_to(self):
         self.assertTrue(p.stat)
         # Linking to a str of a relative path.
         r = rel_join('fileAAA')
-        q.link_to(r)
+        with self.assertWarns(DeprecationWarning):
+            q.link_to(r)
         self.assertEqual(os.stat(r).st_size, size)
         self.assertTrue(q.stat)
 



More information about the Python-checkins mailing list