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

Assertions not rewritten for steps in files with names that don't match Pytest's python_files setting

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

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

評価

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

調査の方向性

まずリンクされている再現プロジェクトを使用し、その後 pytest_bdd.steps.contribute_to_module と pytest.register_assert_rewrite を調査します。pytest のアサーション書き換えパターンに対して step モジュールがどのようにインポートされるかを確認します。steps.py のようなファイル内の steps がアサーション書き換えの対象になるか、またはその制限がユーザーに明確に報告されれば完了です。

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

説明

pytest-bdd steps in files with names that don't match pytest's patterns in thepython_files settings, like steps.py, given.py, when.py then.py, are not picked up by pytests assertion rewriting.

Here's a simple setup to reproduce: https://github.com/blaise-io/pytest-bdd-assertion-rewrite-issue.

In most apps this can be fixed by using pytest.register_assert_rewrite to register modules containing steps, but I'd expect pytest-bdd to either do that for me or for pytest-bdd to warn me about this limitation.

For pytest-bdd to register steps modules magically seemed only possible with heavy monkey patching, as pytest does not allow registering a module for rewriting when the module is already imported. The following code registers the module of a steps for assertion rewriting, which is to demonstrate why monkey patching is a bad idea:

    # append to pytest_bdd.steps.contribute_to_module
    from _pytest.assertion import rewrite
    from six.moves import reload_module
    for hook in sys.meta_path:
        if isinstance(hook, rewrite.AssertionRewritingHook):
            # Add module file name to python_files patterns
            if module.__file__ not in hook.fnpats:
                hook.fnpats.append(module.__file__)
            # Remove module path from checks
            if name in hook._rewritten_names:
                hook._rewritten_names.remove(name)
            # Force-reload the module after our rewrite in setattr
            reload_module(module)
            break
主要言語
Python
スター
1.5k
フォーク
251
平均マージ
43分
マージ済み PR(30日)
2

環境構築

はじめの一歩

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

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

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

似ている issue

Python の issue をもっと見る

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

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