From 041c49fa0ece55584855235fe473fab38babd97b Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Thu, 19 Nov 2020 20:32:42 +0300 Subject: [PATCH 1/2] bpo-42383: pdb: do not fail to restart the target if the current directory changed This commit only adds tests and a news entry. The actual bug was fixed in the earlier commit. --- Lib/test/test_pdb.py | 23 +++++++++++++++++++ .../2020-11-17-14-30-12.bpo-42383.ubl0Y_.rst | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-11-17-14-30-12.bpo-42383.ubl0Y_.rst diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index e1a13cbaf3ef84..2d425bc7c787aa 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1702,6 +1702,29 @@ def test_issue42384_symlink(self): self.assertEqual(stdout.split('\n')[2].rstrip('\r'), expected) + def test_issue42383(self): + with os_helper.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): from test import test_pdb diff --git a/Misc/NEWS.d/next/Library/2020-11-17-14-30-12.bpo-42383.ubl0Y_.rst b/Misc/NEWS.d/next/Library/2020-11-17-14-30-12.bpo-42383.ubl0Y_.rst new file mode 100644 index 00000000000000..ccf2106f28a93d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-11-17-14-30-12.bpo-42383.ubl0Y_.rst @@ -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. From aae8957a0f051dbfd02e6981113a9e5acdf2f157 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Mon, 25 Jan 2021 10:23:10 +0300 Subject: [PATCH 2/2] Fix broken pdb tests --- Lib/test/test_pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 2d425bc7c787aa..6c4eaf318e4480 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1703,7 +1703,7 @@ def test_issue42384_symlink(self): self.assertEqual(stdout.split('\n')[2].rstrip('\r'), expected) def test_issue42383(self): - with os_helper.temp_cwd() as cwd: + with support.temp_cwd() as cwd: with open('foo.py', 'w') as f: s = textwrap.dedent(""" print('The correct file was executed')