KeyError when using Rule keyword with step data tables or DocStrings
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 50/100
Piste de recherche
Commencez dans allure_behave/listener.py, autour des lignes 144-147, puis reproduisez le problème avec test/features/simple/tutorial.feature et test/steps/steps_tutorial.py. Exécutez la commande fournie de Behave Allure formatter et vérifiez que les étapes avec des tables et des DocStrings sous une Rule se terminent correctement sans générer de KeyError et produisent leurs pièces jointes.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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:
- Data tables (tables attached to steps)
- 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
Rulekeyword
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
Rulekeyword is a valid Gherkin construct for organizing scenarios - Behave 1.2.6+ fully supports the
Rulekeyword - This issue prevents using Allure reporting with modern Gherkin best practices
References
- Gherkin Rule keyword documentation: https://cucumber.io/docs/gherkin/reference/#rule
- Behave changelog (Rule support): https://github.com/behave/behave/blob/main/CHANGES.rst
- Langage dominant
- Python
- Étoiles
- 817
- Forks
- 262
- Merge moyen
- 3 h 20 min
- PR mergées (30 j)
- 3
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de allure-framework/allure-python
-
[allure-behave] Steps from tag-excluded scenarios bleed into the next matching scenario's result when hide_excluded=truePeut-être pris @liuyaohui666 l’a pris il y a 45 jours. Ouverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 84/100
-
Added CategoriesOuverte
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
-
Phantom <lambda> teardown entries with unknown status when using pytest 9.1+Peut-être pris @Mohanad49 l’a pris il y a 50 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 58/100
allure-framework/allure-python#918 · 1 réaction ·
-
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
allure-framework/allure-python#903 · 1 commentaire ·
-
Allure step placeholder fails when accessing dataclass attribute `data.name`Peut-être pris @golikovichev l’a pris il y a 155 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
Toutes les issues de allure-framework/allure-python
Issues similaires
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
QuantEcon/lecture-python-programming#642 ·
Les mainteneurs répondent en général sous 1 jour
-
area/config area/profiles comp/cli needs-decision P3 sweeper:risk-compatibility type/feature
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
NousResearch/hermes-agent#133697 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement needs-triage
Difficulté 1/5 Moins d'une heure Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
core
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
vectorize-io/hindsight#5279 ·
Les mainteneurs répondent en général sous 1 jour