Assertions not rewritten for steps in files with names that don't match Pytest's python_files setting
まだ誰も着手していません。
評価
調査の方向性
まずリンクされている再現プロジェクトを使用し、その後 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
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytest-dev/pytest-bdd のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
pytest-dev/pytest-bdd#805 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
pytest-dev/pytest-bdd#785 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
pytest-dev/pytest-bdd#784 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
pytest-dev/pytest-bdd#782 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
pytest-dev/pytest-bdd#780 · リアクション 3 件 ·
pytest-dev/pytest-bdd の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
PedestrianDynamics/pyFDS-Evac#343 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
theskumar/python-dotenv#708 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 2 日以内に返信
-
Docs Timedelta
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
pandas-dev/pandas#69919 ·
メンテナーはふだん 1 日以内に返信
-
API documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
zephyrproject-rtos/west#1009 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信