]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39950: Fix deprecation warning in test for `pathlib.Path.link_to()` (GH-26155...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 16 May 2021 22:35:44 +0000 (15:35 -0700)
committerGitHub <noreply@github.com>
Sun, 16 May 2021 22:35:44 +0000 (15:35 -0700)
(cherry picked from commit 1a08c5ac49b748d5e4e4b508d22d3804e3cd4dcc)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
Lib/pathlib.py
Lib/test/test_pathlib.py

index 94e079fffef600ddcd0cdec0e44ce7bd87133f18..8e6eb48b9767cabc1d03a35cbea46ec51bbd1f29 100644 (file)
@@ -1265,7 +1265,7 @@ class Path(PurePath):
         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
index 6ed08f7e70ce3d37964c2406d7434e87acb59032..55d63d539e550eba61b0e9464cb4613fb5e0c853 100644 (file)
@@ -1934,7 +1934,8 @@ class _BasePathTest(object):
         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)