[3.9] bpo-42383: pdb: do not fail to restart the target if the current directory changed (GH-23412) (#24322)

This commit is contained in:
Andrey Bienkowski 2021-01-26 15:57:58 +00:00 committed by GitHub
parent f2df7958fb
commit f8cfe54e5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View file

@ -1702,6 +1702,29 @@ def bœr():
self.assertEqual(stdout.split('\n')[2].rstrip('\r'), expected) self.assertEqual(stdout.split('\n')[2].rstrip('\r'), expected)
def test_issue42383(self):
with support.temp_cwd() as cwd:
with open('foo.py', 'w') as f:
s = textwrap.dedent("""
print('The correct file was executed')
import os
os.chdir("subdir")
""")
f.write(s)
subdir = os.path.join(cwd, 'subdir')
os.mkdir(subdir)
os.mkdir(os.path.join(subdir, 'subdir'))
wrong_file = os.path.join(subdir, 'foo.py')
with open(wrong_file, 'w') as f:
f.write('print("The wrong file was executed")')
stdout, stderr = self._run_pdb(['foo.py'], 'c\nc\nq')
expected = '(Pdb) The correct file was executed'
self.assertEqual(stdout.split('\n')[6].rstrip('\r'), expected)
def load_tests(*args): def load_tests(*args):
from test import test_pdb from test import test_pdb

View file

@ -0,0 +1,2 @@
Fix pdb: previously pdb would fail to restart the debugging target if it was
specified using a relative path and the current directory changed.