Attribute error in @allure.title when using @pytest.fixture(params=[...]
まだ誰も着手していません。
評価
調査の方向性
トレースバックに示されている @allure.title のフォーマット処理経路と allure_commons.utils.SafeFormatter.get_field から開始し、#670 に記載された動作と比較します。パラメータ化されたフィクスチャの skip ケースとエラーケースを再現し、AttributeError ではなく元の pytest の skip または ValueError が報告されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
@allure.title decorator doesn't correctly formats a title string when using a parametrized fixture and having that fixture skip a test or raise an error:
import pytest
import allure
class TestClass:
@pytest.fixture(params=[1, 2]) # <-- causes AttributeError: 'int' object has no attribute 'one'
# @pytest.fixture()
def params(self):
# will cause AttributeError in allure.title
# if this fixture is skipping tests
pytest.skip('skip')
# or raising an error
raise ValueError('aa')
class _Params:
"""some params every test needs"""
one = 1
two = 2
# but no error if it returns a value
return _Params()
@allure.title('should display "1" {params.one}')
def test_func(self, params): # <-- causes AttributeError: 'int' object has no attribute 'one'
assert params.one == 1
self = <allure_commons.utils.SafeFormatter object at 0x7f1851ab19d0>, field_name = 'params.one', args = (), kwargs = {'param_id': '2', 'params': 2}
def get_field(self, field_name, args, kwargs):
first, rest = _string.formatter_field_name_split(field_name)
obj = self.get_value(first, args, kwargs)
# loop through the rest of the field_name, doing
# getattr or getitem as needed
for is_attr, i in rest:
if is_attr:
> obj = getattr(obj, i)
^^^^^^^^^^^^^^^
E AttributeError: 'int' object has no attribute 'one'
/usr/lib64/python3.12/string.py:305: AttributeError
=================================================================== short test summary info ====================================================================
ERROR p.py::TestClass::test_func[1] - AttributeError: 'int' object has no attribute 'one'
ERROR p.py::TestClass::test_func[2] - AttributeError: 'int' object has no attribute 'one'
====================================================================== 2 errors in 0.14s =======================================================================
This is shadowing the real error or skip in the fixture and is similar to #670
allure-pytest==2.15.0
pytest==8.4.1
- 主要言語
- Python
- スター
- 819
- フォーク
- 261
- 平均マージ
- 3時間 20分
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
allure-framework/allure-python のほかの issue
-
[allure-behave] Steps from tag-excluded scenarios bleed into the next matching scenario's result when hide_excluded=true対応中かも @liuyaohui666 が 47 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
-
theme:pytest
難易度 3/5 1〜2日 初心者へのやさしさ 64/100
allure-framework/allure-python#929 · リアクション 1 件 ·
-
Added Categoriesオープン
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
-
Phantom <lambda> teardown entries with unknown status when using pytest 9.1+対応中かも @Mohanad49 が 51 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
allure-framework/allure-python#918 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
allure-framework/allure-python#903 · コメント 1 件 ·
allure-framework/allure-python の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
Harmony OPeNDAP SubSetter (HOSS) Geographic LARC_CLOUD PREFIRE_SAT2_AUX-SAT R01 production
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
nasa/harmony-autotester#245 ·
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Deltares/imod-python#1928 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
feature
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100