`WarningsRecorder.pop()` returns the last match instead of the first when warning categories are unrelated
メンテナーはふだん 1 日以内に返信
@Aditya-XR がすでに取り組んでいます。
2026年9月24日 から。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- python
- 領域
- testing-qa
調査の方向性
Start at the WarningsRecorder.pop implementation and read TestSubclassWarningPop plus test_recording, especially the existing category-selection loop. Add a regression case using unrelated warning categories and verify that pop returns the first matching warning; run the relevant warning-recorder tests.
索引モデルが issue の本文から書いたものです。
説明
WarningsRecorder.pop() (and pytest.warns(...).pop() / recwarn.pop()) returns the last matching warning instead of the first one when the recorded warnings have categories that are unrelated to each other.
import warnings
def test_pop(recwarn):
warnings.warn("first", UserWarning)
warnings.warn("second", RuntimeWarning)
warnings.warn("third", DeprecationWarning)
assert str(recwarn.pop().message) == "first"
E AssertionError: assert 'third' == 'first'
The docstring says pop returns "the first recorded warning which is an instance of cls, but not an instance of a child class of any other match". None of the three categories is a subclass of another, so the first one should come back. That was also the behaviour before 8.0.
The cause is the "best inexact match" loop added in #11160 (the fix for #10701):
if issubclass(w.category, cls) and (
best_idx is None
or not issubclass(w.category, self._list[best_idx].category)
):
best_idx = i
not issubclass(new, best) is true both when new is more general than best and when the two are unrelated siblings. So every sibling replaces the current best, and the loop ends up on the last one.
The existing tests in TestSubclassWarningPop only use a single parent/child chain, so they don't catch this. test_recording pops a UserWarning and a DeprecationWarning, but both have the message "hello", so it passes whichever one comes back.
Reproduced on main (pytest 9.2.0.dev345+g872117358), Python 3.13.5, Windows 11. The loop was introduced by #11160, so the bug is present since 8.0.0; in 7.4.x pop() returned the first match. I have a fix with regression tests ready and will open a PR.
- 主要言語
- Python
- スター
- 14.6k
- フォーク
- 3.4k
- 平均マージ
- 2日 8時間
- マージ済み PR(30日)
- 30
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytest-dev/pytest のほかの issue
-
monkeypatch.setattr fails to undo on objects with a custom __setattr__ (regression from #14969)対応中かも @Maurenz2530 が 9 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
pytest-dev/pytest#15099 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Allow dotted test filenames (`*.test.py`) via one-line change to `compute_module_name`再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
pytest-dev/pytest#14514 · コメント 6 件 ·
メンテナーはふだん 1 日以内に返信
-
Expose CaptureManager as public API再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンtype: enhancement type: feature-branch
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pytest-dev/pytest#14186 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Docs on warnings filters should note that `ResourceWarning` is often delayed対応中かも @tanishmisra9 が 104 日前に担当しました。 オープンtype: docs
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pytest-dev/pytest#9825 · コメント 7 件 ·
メンテナーはふだん 1 日以内に返信
-
Native TOML numeric faulthandler_timeout is rejected対応中かも @hfycium が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 25/100
pytest-dev/pytest#15132 ·
メンテナーはふだん 1 日以内に返信
pytest-dev/pytest の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Qiskit/qiskit-ibm-runtime#3431 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Lesson] A compatibility-gate rejection is a verdict, not something to overwrite with --accept-riskオープンlesson-submission needs-ac pending-review
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
Ikalus1988/MisakaNet#2870 ·
メンテナーはふだん 1 日以内に返信
-
feature:LinkChecker
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
digitalfabrik/integreat-cms#4594 ·
メンテナーはふだん 5 日以内に返信