@@ -1661,6 +1661,48 @@ def test_errors_in_command(self):
16611661 '(Pdb) ' ,
16621662 ])
16631663
1664+
1665+ def test_issue42384 (self ):
1666+ '''When running `python foo.py` sys.path[0] is an absolute path. `python -m pdb foo.py` should behave the same'''
1667+ script = textwrap .dedent ("""
1668+ import sys
1669+ print('sys.path[0] is', sys.path[0])
1670+ """ )
1671+ commands = 'c\n q'
1672+
1673+ with support .temp_cwd () as cwd :
1674+ expected = f'(Pdb) sys.path[0] is { os .path .realpath (cwd )} '
1675+
1676+ stdout , stderr = self .run_pdb_script (script , commands )
1677+
1678+ self .assertEqual (stdout .split ('\n ' )[2 ].rstrip ('\r ' ), expected )
1679+
1680+ @support .skip_unless_symlink
1681+ def test_issue42384_symlink (self ):
1682+ '''When running `python foo.py` sys.path[0] resolves symlinks. `python -m pdb foo.py` should behave the same'''
1683+ script = textwrap .dedent ("""
1684+ import sys
1685+ print('sys.path[0] is', sys.path[0])
1686+ """ )
1687+ commands = 'c\n q'
1688+
1689+ with support .temp_cwd () as cwd :
1690+ cwd = os .path .realpath (cwd )
1691+ dir_one = os .path .join (cwd , 'dir_one' )
1692+ dir_two = os .path .join (cwd , 'dir_two' )
1693+ expected = f'(Pdb) sys.path[0] is { dir_one } '
1694+
1695+ os .mkdir (dir_one )
1696+ with open (os .path .join (dir_one , 'foo.py' ), 'w' ) as f :
1697+ f .write (script )
1698+ os .mkdir (dir_two )
1699+ os .symlink (os .path .join (dir_one , 'foo.py' ), os .path .join (dir_two , 'foo.py' ))
1700+
1701+ stdout , stderr = self ._run_pdb ([os .path .join ('dir_two' , 'foo.py' )], commands )
1702+
1703+ self .assertEqual (stdout .split ('\n ' )[2 ].rstrip ('\r ' ), expected )
1704+
1705+
16641706def load_tests (* args ):
16651707 from test import test_pdb
16661708 suites = [
0 commit comments