allure-framework / allure-framework/allure-python

allure-behave: extend scenario_history_id to use optional environment variable

Offen
#880 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
814
Forks
260
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### 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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne in allure-behave/src/utils.py bei scenario_history_id(scenario) und prüfe anschließend, wie die zurückgegebene History-ID verwendet wird, wenn Allure-Ergebnisse gesammelt werden. Als abgeschlossen gilt die Änderung, wenn ein optionaler ALLURE_HISTORY_ID-Wert Ausführungen voneinander unterscheidet, während die vorhandenen Eingaben feature, scenario und scenario-row weiterhin die ID bestimmen, wenn die Variable nicht vorhanden ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
testing-qa
Issue-Typ
Feature
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.