Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

only_rerun with exception raised from fixture teardown reruns test but report previous runs as failure

オープン
#261 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

@hfycium がすでに取り組んでいます。

2026年10月6日 から。

  • #262 @shlompy による — マージされずにクローズ
  • #385 @hfycium による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
testing

調査の方向性

setup、call、teardown のレポート処理パスから始め、例外フィルター rerun_only がテストを再実行するかどうかをどのように判断するかを追跡します。fixture-teardown の MyCustomError の例を再現し、teardown によってトリガーされた再実行が、以前の実行による失敗として報告されるのではなく、最終結果に含まれることを確認します。

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

説明

Hi.
I have a need to do some checks in a fixture teardown to determine whether a test should rerun or not.
Because rerunfailures only allows filtering based on exception, what I had in mind is that to check whatever I want in the fixture and raise the custom exception so the test will rerun.
However, while this package detects a rerun is needed when processing the teardown report, the call (test) report was already processed and it was not marked to be rerun, because the rerun_only condition didn't match the test exception, as the custom exception was raised from the fixture.

Eventually, the test does re-run until it pass, but pytest still report the test failure outcomes.

Note that the reruns works just fine when not using only_rerun condition.

Example code:

import random

import pytest

class MyCustomError(Exception):
    pass

@pytest.fixture
def rerun_custom_checker(request):
    yield

    if request.node.rep_call.outcome == "passed":
        return

    raise MyCustomError()


@pytest.mark.flaky(reruns=10, reruns_delay=1, only_rerun=["MyCustomError"])
def test_example(rerun_custom_checker):

    i = random.randint(2, 4)
    if i != 3:
        assert False
image

What I had in mind, is to pre-process the reports and set a flag whether rerun is needed, if it was found to be needed for setup/call/teardown.
Then, when processing the reports as usual, and just check for this flag.

Something like:
image

I can raise a PR with that change, assuming this solution is acceptable (It works fine when testing this change)

主要言語
Python
スター
480
フォーク
110
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

pytest-dev/pytest-rerunfailures のほかの issue

pytest-dev/pytest-rerunfailures の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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