allure-framework / allure-framework/allure-python

Allure step placeholder fails when accessing dataclass attribute `data.name`

オープン
#896 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
814
フォーク
260
PR マージ指標
30日以内にマージされた PR はありません

説明

With the usage provided in [step_placeholder.rst](https://github.com/allure-framework/allure-python/blob/master/allure-pytest/examples/step/step_placeholder.rst), I used Allure step placeholders to reference a property on a Python `dataclass` passed as a function argument. Using `data.name` in the step title raises an `AttributeError` during step rendering.

#### Expected behavior

Allure should resolve `data.name` and display the value of the `name` attribute in the step title like Create opportunity: Auto QA Example

#### Actual behavior

Allure raises an exception before the step executes: `AttributeError: 'str' object has no attribute 'get('name)'`

MWE of dataclass used

```python

@dataclass
class OpportunityData:
"""Data class for opportunity test data."""

name: str
expected_revenue: str
email: Optional[str] = None
phone: Optional[str] = None
state: Optional[str] = None
street: Optional[str] = None
zip_code: Optional[str] = None
```

Factory function for Opportunity creation
```python
def create_opportunity_data() -> OpportunityData:
"""Factory function to create OpportunityData for tests."""


data = OpportunityData(
name=f"Auto QA {fake.company()}",
expected_revenue=_generate_expected_revenue(),
email = fake.email()
phone = fake.phone_number()
street = fake.street_address()
zip_code = fake.zipcode()
state=fake.random_element(STATE_OPTIONS),
)

return data
```
Test Opportunity file
```python
@allure.title("Test opportunity creation with all main fields")
@allure.testcase("CRM-002")
@pytest.mark.regression
def test_opportunity_creation_full(opportunity_page: OpportunityPage, app_instance: App) -> None:

# ARRANGE
data = create_opportunity_data(full=True, opportunity_type="CRM Multi-Year")

# ACT
opportunity_page.create_opportunity(data)

# ASSERT
opportunity_page.verify_opportunity_saved(data.name)

```
Opportunity Page class
```python
@allure.step("Create opportunity: {data.name}")
def create_opportunity(self, data: "OpportunityData", base_url: str) -> Self:
"""High-level method to create an opportunity with provided data."""


# Fill main form fields
self.fill_opportunity_name(data.name)
self.fill_expected_revenue(data.expected_revenue)

```

Call stack

```
app_instance =

@allure.title("Test opportunity creation with minimal fields")
@allure.testcase("CRM-001")
@pytest.mark.smoke
def test_opportunity_creation_flow(opportunity_page: OpportunityPage, app_instance: App) -> None:

# ARRANGE
data = create_opportunity_data(opportunity_type="Monitoring")

# ACT
> opportunity_page.create_opportunity(data, app_instance.base_url)
E AttributeError: 'str' object has no attribute 'get('name)'
```

#### Notes

* `data` is a dataclass instance, not a dict.
* Attribute access works inside the function body.
* The error occurs during Allure step title formatting.

#### Environment

* Python 3.12
* allure-pytest==2.15.2
* pytest==8.4.2
* pytest-playwright==0.7.2
* mypy==1.19.0
* mypy-extensions==1.1.0

Does allure step placeholders accept only strings?

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

step_placeholder.rst の使用箇所から始め、Python 3.12 と allure-pytest 2.15.2 を使った dataclass の例で失敗を再現します。step-title プレースホルダーのレンダリングを追跡し、dataclass 属性へのアクセスのカバレッジを追加します。step が AttributeError を発生させずに解決済みの名前を表示すれば完了です。

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

評価

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

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

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