allure-framework / allure-framework/allure-python

allure-behave: extend scenario_history_id to use optional environment variable

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

説明

### Context

# allure-behave: extend scenario_history_id to use optional environment variable

We have a problem where we want to run the same test-suite in different environments. For example:

1. **Execute Test-Suite for Different Browser:** Firefox, Chrome, ... (i.e. 'BROWSER=firefox behave' 'BROWSER=chromium behave' etc.)
2. **Execute Test-Suite for Different Systems:** Linux armx64, Linux amd64, Win amd64, ...

If we collect all JSON allure-results and generate an allure report we only see **one** result for each test-scenario. Other executions are shown only in the "retries" section. We need to change the history ID so that each execution appears as a separate test.

We want to solve this by adding additional information into the historyId. It would have been nice to use additional user-modifiable information from the Scenario object, but this is not possible since scenario_history_id() is called before the before_scenario() hook (environment.py). Therefore not action in the before_scenario hook function (like changing scenario name or adding other information, can impact the historyId.

Thus, we designed a solution that uses an environment variable to pass this information. Our proposal is to the set an environment variable in `environment.py` that is used to influence the `historyId`.

In `allure-python/allure-behave/src/utils.py`:

```python
def scenario_history_id(scenario) -> str:
"""
Create a historyId for a scenario.
- Always based on feature name and scenario name
- Optional: can append a value from an environment variable
"""
parts = [scenario.feature.name, scenario.name]

if hasattr(scenario, "_row") and scenario._row:
row = scenario._row
parts.extend([f"{name}={value}" for name, value in zip(row.headings, row.cells)])

# Optional: append environment variable to differentiate runs
history_id = os.getenv("ALLURE_HISTORY_ID")
if history_id:
parts.append(history_id)

return md5(*parts)
```

To use this feature, add the environment variable in `environment.py`:

```python
from enum import Enum
import os

class Option(str, Enum):
OPTION_A = "Option A"
OPTION_B = "Option B"

def before_all(context):
os.environ["ALLURE_HISTORY_ID"] = Option.OPTION_B.name
```

Pull Request: #879

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

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

調査の方向性

allure-behave/src/utils.py の scenario_history_id(scenario) から始め、Allure の結果が収集される際に、返された履歴 ID がどのように使用されるかを確認してください。ALLURE_HISTORY_ID の任意の値によって実行を区別でき、変数が存在しない場合は既存の feature、scenario、scenario-row の入力によって引き続き ID が決定されれば完了です。

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

評価

技術スタック
python
領域
testing-qa
issue の種類
機能追加
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

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

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