GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set by zangjiucheng · Pull Request #151952 · python/cpython

Conversation

@zangjiucheng

@zangjiucheng zangjiucheng commented Jun 22, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

  • Several tests in test_inspect, test_import, test_importlib.test_util,
    test_py_compile, and test_compileall assume the default __pycache__
    bytecode layout and fail when the suite is run with PYTHONPYCACHEPREFIX set.
  • Fix: neutralize sys.pycache_prefix (and PYTHONPYCACHEPREFIX for
    subprocess-based tests) where that assumption is made so tests are environment-independent.
  • The key pattern for subprocess tests: assert_python_ok() runs with -I
    (isolated mode), which ignores PYTHONPYCACHEPREFIX, so the expected cached
    path must be computed with sys.pycache_prefix=None to match.
  • Issue: Some tests fail when __pycache__ prefix is set #151626

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zangjiucheng
Fix tests in test_compileall, test_import, test_importlib, test_py_co…
e20d6a2
…mpile, and test_inspect to neutralize PYTHONPYCACHEPREFIX
@zangjiucheng
zangjiucheng requested review from FFY00, brettcannon, ericsnowcurrently, ncoghlan and warsaw as code owners June 22, 2026 22:12
@bedevere-app bedevere-app Bot mentioned this pull request Jun 22, 2026
Some tests fail when __pycache__ prefix is set #151626
Closed
15 tasks
@bedevere-app bedevere-app Bot added the awaiting review label Jun 22, 2026
@vstinner

vstinner commented Jun 23, 2026

Copy link
Copy Markdown
Member

test_inspect fails on Windows. Example:


FAIL: test_details_option_with_aliased_target (test.test_inspect.test_inspect.TestModuleCLI.test_details_option_with_aliased_target)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\a\cpython\cpython\Lib\test\test_inspect\test_inspect.py", line 6676, in test_details_option_with_aliased_target
    self.assertEqual(output_lines, expected_lines)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Lists differ: ['Tar[116 chars], 'Cached: None', 'Line: 98', ''] != ['Tar[116 chars], 'Cached: __pycache__\\frozencpython-316.pyc', 'Line: 98', '']

First differing element 3:
'Cached: None'
'Cached: __pycache__\\frozencpython-316.pyc'

  ['Target: ntpath:join (looked up as "os:path.join")',
   'Origin: frozen',
   'Source: D:\\a\\cpython\\cpython\\Lib\\ntpath.py',
-  'Cached: None',
+  'Cached: __pycache__\\frozencpython-316.pyc',
   'Line: 98',
   '']
zangjiucheng reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@zangjiucheng

zangjiucheng commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

I will resolve this today :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zangjiucheng and others added 2 commits June 23, 2026 09:32
@zangjiucheng @claude
fix(pythongh-151626): handle frozen os.path on Windows in test_aliase…
fdc59f3
…d_target

On Windows, os.path resolves to ntpath which is a frozen module
(origin='frozen', cached=None). Calling cache_from_source('frozen')
fabricates a nonsensical path that mismatches the subprocess output of
None. Guard the cache_from_source call on cached being non-None.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@zangjiucheng
fix(test_inspect): add method to handle cached paths for frozen modul…
84f1e16
…es, fix NEWS.d with no test target
gpshead
gpshead approved these changes Jul 1, 2026
View reviewed changes

@gpshead gpshead left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice test suite cleanup, thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

zangjiucheng reacted with heart emoji
All reactions
  • ❤️ 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jul 1, 2026
@gpshead gpshead added needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Jul 1, 2026
@gpshead
gpshead merged commit 564c58c into python:main Jul 1, 2026
61 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Jul 1, 2026

Copy link
Copy Markdown

Thanks @zangjiucheng for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jul 1, 2026
@miss-islington-app

miss-islington-app Bot commented Jul 1, 2026

Copy link
Copy Markdown

Sorry, @zangjiucheng and @gpshead, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 564c58c718bc3de9cf3d9bc20cdc06317411c1cd 3.14
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app miss-islington-app Bot assigned gpshead Jul 1, 2026
@bedevere-app

bedevere-app Bot commented Jul 1, 2026

Copy link
Copy Markdown

GH-152736 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Jul 1, 2026
@miss-islington-app

miss-islington-app Bot commented Jul 1, 2026

Copy link
Copy Markdown

Sorry, @zangjiucheng and @gpshead, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 564c58c718bc3de9cf3d9bc20cdc06317411c1cd 3.13
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gpshead gpshead removed needs backport to 3.13 only security fixes needs backport to 3.14 bugs and security fixes labels Jul 1, 2026
gpshead pushed a commit that referenced this pull request Jul 1, 2026
@miss-islington @zangjiucheng
[3.15] gh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set (…
4bacb0c
…GH-151952) (#152736)

gh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set (GH-151952)

Fix tests in test_compileall, test_import, test_importlib, test_py_compile, and test_inspect to neutralize PYTHONPYCACHEPREFIX
(cherry picked from commit 564c58c)

Co-authored-by: Jiucheng(Oliver) <[email protected]>
@bedevere-app

bedevere-app Bot commented Jul 1, 2026

Copy link
Copy Markdown

GH-152744 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gpshead added a commit that referenced this pull request Jul 1, 2026
@gpshead @zangjiucheng
[3.14] gh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set (…
7087839
…GH-151952) (#152744)

Fix tests in test_compileall, test_import, test_importlib, test_py_compile, and test_inspect to neutralize PYTHONPYCACHEPREFIX
(cherry picked from commit 564c58c)

Co-authored-by: Jiucheng(Oliver) <[email protected]>
gpshead added a commit that referenced this pull request Jul 1, 2026
@miss-islington @gpshead @zangjiucheng
[3.13] gh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set (…
5bf5eea
…GH-151952) (GH-152744) (#152748)

[3.14] gh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set (GH-151952) (GH-152744)

Fix tests in test_compileall, test_import, test_importlib, test_py_compile, and test_inspect to neutralize PYTHONPYCACHEPREFIX
(cherry picked from commit 564c58c)
(cherry picked from commit 7087839)

Co-authored-by: Gregory P. Smith <[email protected]>
Co-authored-by: Jiucheng(Oliver) <[email protected]>
maurycy added a commit to maurycy/cpython that referenced this pull request Jul 1, 2026
@maurycy
Merge branch 'main' into maurycy/bye-abba
da7d768
* main: (266 commits)
  pythongh-151626: Fix tests that fail when PYTHONPYCACHEPREFIX is set (pythonGH-151952)
  pythongh-152728: IDLE - move 3 toplevel fix_xyz functions to idlelb.util (python#152729)
  pythongh-152711: Add pythoninfo-build command to Platforms/Android (python#152713)
  pythongh-152715: Add pythoninfo-build command to Platforms/Apple (python#152716)
  pythongh-152433: Windows: enable mmapmodule for UWP (python#152473)
  pythongh-152433: Windows: use GetFileSizeEx instead of GetFileSize for memory mapped files (python#152383)
  pythonGH-81881: Raise `SpecialFileError` for sockets and devices in `shutil.copyfile` (python#142693)
  pythongh-152502: Detect the curses mouse interface and is_* methods portably (pythonGH-152705)
  pythongh-145857: Replace `DELETE_GLOBAL` with `PUSH_NULL; STORE_GLOBAL` (pythonGH-146314)
  pythongh-145854: Replace `DELETE_NAME` with `PUSH_NULL; STORE_NAME` (pythonGH-146006)
  pythongh-152680: Detect container/VM in test.pythoninfo (python#152668)
  pythongh-152682: Fix NULL dereference on OOM in `symtable_visit_type_param_bound_or_default` (python#152684)
  pythongh-151881: Skip tk_inactive negativity check on Windows (pythonGH-152683)
  pythongh-152546: Refactor `mappingproxy.__new__` to use `PyDictProxy_New` (python#152547)
  pythongh-151126: Fix a possible crash during the startup with no memory under `Py_STACKREF_DEBUG` (python#152478)
  pythongh-152635: Raise MemoryError when the lock allocation fails in `_interpchannels.create()` (python#152642)
  pythongh-151029: Fix `test_remote_exec_deleted_static_executable` on static installed builds (pythonGH-152653)
  pythongh-121249: Deprecate using F/D type codes in the struct module (python#152309)
  pythongh-152192: Fix JUMP_BACKWARD passing a truncated oparg to the jit tracer (pythonGH-152382)
  Don't require the `_test{internal}capi` modules in `test_monitoring.py` (python#152311)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead gpshead approved these changes
@brettcannon brettcannon Awaiting requested review from brettcannon brettcannon is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gpshead gpshead

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@zangjiucheng @vstinner @gpshead
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.