Skip to content

Commit 639ee0d

Browse files
add optional historyId as environment variable
1 parent 6ad9c8f commit 639ee0d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

allure-behave/src/utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import csv
22
import io
3+
import os
34
from enum import Enum
45
from pathlib import Path
56
from behave.runner_util import make_undefined_step_snippet
@@ -26,11 +27,23 @@ def scenario_name(scenario):
2627
return scenario.name if scenario.name else scenario.keyword
2728

2829

29-
def scenario_history_id(scenario):
30+
def scenario_history_id(scenario) -> str:
31+
"""
32+
Create a historyId for a scenario.
33+
- Always based on feature name and scenario name
34+
- Optional: can append a value from an environment variable
35+
"""
3036
parts = [scenario.feature.name, scenario.name]
31-
if scenario._row:
37+
38+
if hasattr(scenario, "_row") and scenario._row:
3239
row = scenario._row
33-
parts.extend([f'{name}={value}' for name, value in zip(row.headings, row.cells)])
40+
parts.extend([f"{name}={value}" for name, value in zip(row.headings, row.cells)])
41+
42+
# Optional: append environment variable to differentiate runs
43+
history_id = os.getenv("HISTORY_ID")
44+
if history_id:
45+
parts.append(history_id)
46+
3447
return md5(*parts)
3548

3649

0 commit comments

Comments
 (0)