Skip to content

test_pdb fails: Unexpected sys.path[0] behavior with PYTHONSAFEPATH set #123121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
xncbf opened this issue Aug 18, 2024 · 5 comments
Closed

test_pdb fails: Unexpected sys.path[0] behavior with PYTHONSAFEPATH set #123121

xncbf opened this issue Aug 18, 2024 · 5 comments
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@xncbf
Copy link
Contributor

xncbf commented Aug 18, 2024

Bug report

Bug description:

Issue:
The test_safe_path function in test_pdb.py is failing. When PYTHONSAFEPATH is set to '1', sys.path[0] still includes the current working directory, which is unexpected.

Steps to Reproduce:

  1. Run the Python test suite, specifically focusing on test_pdb.
  2. Observe that test_safe_path fails with the following error:
AssertionError: 'sys.path[0] is /Users/joon/projects/cpython/build/test_python_68610æ/tempcwd' unexpectedly found in '> /Users/joon/projects/cpython/build/test_python_68610æ/tempcwd/main.py(2)<module>()
-> import sys
(Pdb) sys.path[0] is /Users/joon/projects/cpython/build/test_python_68610æ/tempcwd/$PYTHONPATH
The program finished and will be restarted
> /Users/joon/projects/cpython/build/test_python_68610æ/tempcwd/main.py(2)<module>()
-> import sys
(Pdb) 
'

Expected Behavior:
When PYTHONSAFEPATH is set to '1', sys.path[0] should not include the current working directory.

Actual Behavior:
sys.path[0] includes the current working directory, and there's an unexpected $PYTHONPATH appended to the path.

Environment:

  • Python version: 3.14.0
  • OS: macos sonoma 14.1.1 (apple silicon)

#121724

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

@xncbf xncbf added the type-bug An unexpected behavior, bug, or error label Aug 18, 2024
@Eclips4
Copy link
Member

Eclips4 commented Aug 18, 2024

cc @gaogaotiantian

@picnixz picnixz added the tests Tests in the Lib/test dir label Aug 18, 2024
@picnixz picnixz changed the title [BUG] test_pdb fails: Unexpected sys.path[0] behavior with PYTHONSAFEPATH set test_pdb fails: Unexpected sys.path[0] behavior with PYTHONSAFEPATH set Aug 18, 2024
@picnixz picnixz changed the title test_pdb fails: Unexpected sys.path[0] behavior with PYTHONSAFEPATH set test_pdb fails: Unexpected sys.path[0] behavior with PYTHONSAFEPATH set Aug 18, 2024
@gaogaotiantian
Copy link
Member

gaogaotiantian commented Aug 18, 2024

How did you run test_safe_path with PYTHONSAFEPATH = 1? It should be skipped (not that it's what I had in mind when I wrote the test).

    @unittest.skipIf(sys.flags.safe_path,
                     'PYTHONSAFEPATH changes default sys.path')
    def _run_pdb(self, pdb_args, commands,
                 expected_returncode=0,
                 extra_env=None):

@xncbf
Copy link
Contributor Author

xncbf commented Aug 19, 2024

./python.exe -m test test_pdb
./python.exe -m test test_pdb --forever

The above command fails when executed after the build. No other preliminary work is needed.

@gaogaotiantian
Copy link
Member

Are you able to repro this with

./python.exe -m test test_pdb -m test_safe_path

Can you copy/paste the full output? Is it because of mac that the test actually ran?

@gaogaotiantian gaogaotiantian added the pending The issue will be closed if no feedback is provided label Oct 24, 2024
@picnixz picnixz removed the pending The issue will be closed if no feedback is provided label Dec 2, 2024
@picnixz
Copy link
Member

picnixz commented Dec 2, 2024

Closing as cannot reproduce since the OP did not reply for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants