diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-01-21 07:36:19 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-21 07:36:19 (GMT) |
commit | 22f73bd9f1fc573d5c998f345b66c29f7ca6614d (patch) | |
tree | 3d2a2dd2400072cd178010b26e9dfd00bd5049a5 | |
parent | d013b241352e902389f955f8f99d75f16c124ee2 (diff) | |
download | cpython-22f73bd9f1fc573d5c998f345b66c29f7ca6614d.zip cpython-22f73bd9f1fc573d5c998f345b66c29f7ca6614d.tar.gz cpython-22f73bd9f1fc573d5c998f345b66c29f7ca6614d.tar.bz2 |
bpo-46425: Fix direct invocation of `test_contextlib` (GH-30681)
-rw-r--r-- | Lib/test/test_contextlib.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py index bc8e4e4..e238548 100644 --- a/Lib/test/test_contextlib.py +++ b/Lib/test/test_contextlib.py @@ -1117,9 +1117,15 @@ class TestSuppress(unittest.TestCase): class TestChdir(unittest.TestCase): + def make_relative_path(self, *parts): + return os.path.join( + os.path.dirname(os.path.realpath(__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 @@ class TestChdir(unittest.TestCase): 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 @@ class TestChdir(unittest.TestCase): 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: |