allure-framework / allure-framework/allure-python

[allure-behave] Steps from tag-excluded scenarios bleed into the next matching scenario's result when hide_excluded=true

未关闭 适合新手
#902 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
814
派生
260
PR 合并指标
30 天内没有已合并 PR

描述

## Environment
- allure-behave: 2.15.3
- allure-commons: (run `pip show allure-commons`)
- behave: 1.3.3
- Python: 3.12

## Describe the Bug

When running behave with a tag filter (e.g. `-t ETS-TC-372`) and
`-D AllureFormatter.hide_excluded=true`, the Allure result JSON for the
**matching scenario** accumulates steps from all tag-excluded scenarios that
appeared before it in the same feature file.

For example: if Sample.feature has 12 scenarios before ETS-TC-372, and
those 12 scenarios collectively have 179 steps, the result JSON for ETS-TC-372
shows 227 steps (179 orphaned + 48 real) instead of 48.

## Root Cause

Behave calls `formatter.step(step)` for **every** scenario — including
tag-excluded ones — because `show_skipped=True` by default
(`run_scenario or show_skipped` in `Scenario.run()`).

This schedules excluded scenario steps into `AllureListener.self.steps` (a
`deque`).

In `stop_scenario()`, excluded scenarios hit the `should_drop_excluded=True`
branch and call `self.logger.drop_test(uuid)` immediately, **without ever
calling `flush_steps()` or clearing the deque**. All accumulated steps remain
in the deque.

When the first *matching* scenario runs, its steps are appended to the
already-populated deque. `match_step()` pops from the front (FIFO), consuming
the orphaned steps and stamping them into the matching scenario's `TestResult`.

## Reproduction Steps

1. Create a feature file with 5+ scenarios where only the last one has
`@target-tag`.
2. Run:
```bash
behave -t target-tag my.feature \
--format allure_behave.formatter:AllureFormatter \
--outfile allure-results \
-D AllureFormatter.hide_excluded=true
3. Inspect allure-results/*-result.json — the step count will be
(sum of all excluded scenario steps) + (target scenario steps).

Expected Behaviour

The result JSON for the matching scenario should contain only its own
steps.

Fix

In AllureListener.stop_scenario(), clear the deque before dropping the
test so orphaned steps do not leak into the next scenario:

# listener.py — stop_scenario()
if should_drop_skipped_by_option or should_drop_excluded:
self.steps.clear() # ← add this line
self.logger.drop_test(self.current_scenario_uuid)

This one-line fix prevents accumulated steps from tag-excluded scenarios
bleeding into any subsequent scenario's result.

贡献指南

打开贡献指南

调研方向

从 listener.py 中被丢弃排除场景的 AllureListener.stop_scenario() 开始,使用 hide_excluded=true 通过提供的 behave 命令复现该问题。检查生成的 allure-results/*-result.json 文件;当匹配场景的结果只包含其自身的步骤,不包含之前按标签排除的场景中的步骤时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
testing-qa
Issue 类型
缺陷
难度
1/5
预计耗时
1 小时以内
活跃度
冷清
描述清晰度
描述清楚
新手友好度
84/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。