From d39c73c1208f1fb4c644d0f418fdcb7876d1c345 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 19 Jan 2022 10:15:31 +0300 Subject: [PATCH 1/2] bpo-46425: fix direct invocation of `test_contextlib` --- Lib/test/test_contextlib.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index bc8e4e4e2918fb..6e3fda6bab0d26 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -1117,9 +1117,15 @@ def test_cm_is_reentrant(self): class TestChdir(unittest.TestCase): + def make_relative_path(self, *parts): + return os.path.join( + os.path.dirname(os.path.normpath(__file__)), + *parts, + ) + def test_simple(self): old_cwd = os.getcwd() - target = os.path.join(os.path.dirname(__file__), 'data') + target = self.make_relative_path('data') self.assertNotEqual(old_cwd, target) with chdir(target): @@ -1128,8 +1134,8 @@ def test_simple(self): def test_reentrant(self): old_cwd = os.getcwd() - target1 = os.path.join(os.path.dirname(__file__), 'data') - target2 = os.path.join(os.path.dirname(__file__), 'ziptestdata') + target1 = self.make_relative_path('data') + target2 = self.make_relative_path('ziptestdata') self.assertNotIn(old_cwd, (target1, target2)) chdir1, chdir2 = chdir(target1), chdir(target2) @@ -1145,7 +1151,7 @@ def test_reentrant(self): def test_exception(self): old_cwd = os.getcwd() - target = os.path.join(os.path.dirname(__file__), 'data') + target = self.make_relative_path('data') self.assertNotEqual(old_cwd, target) try: From 8218741e2e06ec5cbf9d7844312719a0c7ddef6d Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 19 Jan 2022 11:48:40 +0300 Subject: [PATCH 2/2] Address review --- Lib/test/test_contextlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index 6e3fda6bab0d26..e238548be9e2be 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -1119,7 +1119,7 @@ def test_cm_is_reentrant(self): class TestChdir(unittest.TestCase): def make_relative_path(self, *parts): return os.path.join( - os.path.dirname(os.path.normpath(__file__)), + os.path.dirname(os.path.realpath(__file__)), *parts, )