Order-dependent failure: test_profiling CLI test fails after test_importlib.test_util
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Summary
I found an order-dependent test failure on current main.
A test_profiling sampling CLI test passes when run alone, but fails when run after test_importlib.test_util.
Environment
- OS: Windows NT 10.0.26200.0
- CPython commit:
449122ed0dbdb6a545af4927c59f4c80ee15c515 - Debug build:
PCbuild\amd64\python_d.exe - Release build: also reproduced
- Branch:
investigate/deep-cpython-bug-hunt
Reproduction
PCbuild\amd64\python_d.exe -m unittest -v test.test_importlib.test_util test.test_profiling.test_sampling_profiler.test_cli.TestSampleProfilerCLI.test_cli_module_argument_parsing
The same profiling test passes when run alone.
Actual behavior
The test fails with:
profiling.sampling.errors.SamplingModuleNotFoundError: Module 'mymodule' not found.
Expected behavior
The profiling CLI test should pass regardless of whether test_importlib.test_util ran earlier in the same process.
Investigation
The profiling CLI test patches:
importlib.util.find_spec
However, after running test_importlib.test_util, importlib.util and sys.modules["importlib.util"] appear to refer to different module objects.
The CLI code calls through its own imported module reference:
profiling.sampling.cli.importlib.util.find_spec
So the mock on the global importlib.util.find_spec does not intercept the lookup, and the CLI tries to resolve the fake module name normally.
That leads to:
SamplingModuleNotFoundError: Module 'mymodule' not found.
I could not find an existing open issue or PR covering this failure.
Possible fix
The smallest fix may be to patch the symbol at the point where it is used, for example:
profiling.sampling.cli.importlib.util.find_spec
inside the profiling CLI tests, or alternatively to avoid this mock by using a real temporary module.
I am happy to prepare a focused test-only PR if that direction sounds reasonable.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs
- gh-152675
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 test.test_importlib.test_util 和 test.test_profiling.test_sampling_profiler.test_cli.TestSampleProfilerCLI.test_cli_module_argument_parsing 开始,然后在 Windows 上运行报告中的 unittest 命令。检查 mock 目标是否与 profiling.sampling.cli 使用的模块引用相符。CLI 测试能够单独通过,并且在 test_importlib.test_util 之后也能通过,即表示完成;查看关联的 PR gh-152675 了解当前工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- testing-qa
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100