Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

KeyError when using Rule keyword with step data tables or DocStrings

Aperta
#886 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
testing

Direzione di ricerca

Inizia in allure_behave/listener.py, intorno alle righe 144-147, quindi riproduci il problema con test/features/simple/tutorial.feature e test/steps/steps_tutorial.py. Esegui il comando fornito di Behave Allure formatter e verifica che gli step con tables e DocStrings all'interno di una Rule vengano completati correttamente senza generare un KeyError e producano i relativi allegati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Report:

Environment

  • OS: Windows
  • Python version: 3.12.10
  • behave version: 1.3.1
  • allure-behave version: 2.15.2
  • allure-commons version: (auto-installed with allure-behave)
  • allure commandline version: 2.35.1

Description

When using the Rule keyword (introduced in Behave 1.2.6) in feature files, allure-behave formatter throws a KeyError: None exception when processing steps that contain:

  1. Data tables (tables attached to steps)
  2. DocStrings (multi-line text enclosed in triple quotes """)

Expected Behavior

The Allure formatter should successfully process scenarios under a Rule that contain steps with data tables or DocStrings, just as it does for scenarios without the Rule keyword.

Actual Behavior

The formatter crashes with a KeyError: None traceback when attempting to attach step data (tables or text) to the Allure report.

Steps to Reproduce

1. Create a feature file with Rule and data table

File: test/features/simple/tutorial.feature

Feature: showing off behave

	Rule: Basic arithmetic operations

		Scenario: Passing a table as a data through step
			Given we have behave installed
			When we pass a table as a data through step
				| number1 | number2 | result |
				| 2       | 3       | 5      |
				| 4       | 5       | 9      |
			Then behave should be able to read the table
2. Create step definitions

File: test/steps/steps_tutorial.py

from behave import given, when, then

@given('we have behave installed')
def step_impl(context):
    pass

@when('we pass a table as a data through step')
def step_impl(context):
    assert context.table

@then('behave should be able to read the table')
def step_impl(context):
    pass
3. Run with Allure formatter
behave -f allure_behave.formatter:AllureFormatter -o allure_result_folder
4. Observe the error
Exception KeyError: None
Traceback (most recent call last):
  ...
  File "allure_behave/listener.py", line 147, in start_behave_step
    self.logger.attach_data(uuid4(), step_table(step), name='.table', attachment_type=AttachmentType.CSV)
  File "allure_commons/reporter.py", line 163, in attach_data
    file_name = self._attach(uuid, name=name, attachment_type=attachment_type,
  File "allure_commons/reporter.py", line 153, in _attach
    self._items[last_uuid].attachments.append(attachment)
  File "allure_commons/reporter.py", line 33, in __getitem__
    return self.thread_context.__getitem__(item)
KeyError: None

Additional Testing

Works ✅
  • Simple scenarios under Rule (no tables/DocStrings)
  • Scenario Outlines with Examples tables under Rule
  • All scenario types WITHOUT Rule keyword
Fails ❌
  • Steps with data tables under Rule
  • Steps with DocStrings under Rule
Test Results Matrix
Scenario Type Without Rule With Rule
Simple scenario ✅ Works ✅ Works
Scenario Outline with Examples ✅ Works ✅ Works
Step with data table ✅ Works ❌ Fails
Step with DocString ✅ Works ❌ Fails

Root Cause Analysis

The issue appears to be in allure_behave/listener.py at line 147 (data tables) and line 144 (DocStrings). When processing scenarios under a Rule, the last_uuid is None, causing the attachment operation to fail when trying to access self._items[last_uuid].

The Rule hierarchy creates a different context structure that the formatter doesn't handle correctly when attaching step data.

Suggested Fix

The start_behave_step method in allure_behave/listener.py needs to properly handle the context hierarchy when scenarios are nested under a Rule. The last_uuid should be correctly resolved even when scenarios are children of a Rule element.

Additional Context

  • The Rule keyword is a valid Gherkin construct for organizing scenarios
  • Behave 1.2.6+ fully supports the Rule keyword
  • This issue prevents using Allure reporting with modern Gherkin best practices

References

Lingua principale
Python
Stelle
817
Fork
262
Merge medio
3h 20m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di allure-framework/allure-python

Tutte le issue di allure-framework/allure-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.