python / python/cpython

Order-dependent failure: test_profiling CLI test fails after test_importlib.test_util

オープン
#152,659 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

tests type-bug
主要言語
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず test.test_importlib.test_util と test.test_profiling.test_sampling_profiler.test_cli.TestSampleProfilerCLI.test_cli_module_argument_parsing から始め、その後、報告されている unittest コマンドを Windows で実行します。mock の対象が profiling.sampling.cli で使用されているモジュール参照と一致しているか確認します。CLI テストが単独で、また test_importlib.test_util の後でもパスすれば完了です。現在の作業については、リンクされている PR gh-152675 を確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
testing-qa
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。