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