Title: KeyError when using Rule keyword with step data tables or DocStrings · Issue #886 · allure-framework/allure-python · GitHub
Open Graph Title: KeyError when using Rule keyword with step data tables or DocStrings · Issue #886 · allure-framework/allure-python
X Title: KeyError when using Rule keyword with step data tables or DocStrings · Issue #886 · allure-framework/allure-python
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 Rul...
Open Graph 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 versio...
X 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 versio...
Opengraph URL: https://github.com/allure-framework/allure-python/issues/886
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"KeyError when using Rule keyword with step data tables or DocStrings","articleBody":"# Bug Report: \n\n## Environment\n- **OS**: Windows\n- **Python version**: 3.12.10\n- **behave version**: 1.3.1\n- **allure-behave version**: 2.15.2\n- **allure-commons version**: (auto-installed with allure-behave)\n- **allure commandline version**: 2.35.1\n\n## Description\nWhen 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:\n1. Data tables (tables attached to steps)\n2. DocStrings (multi-line text enclosed in triple quotes `\"\"\"`)\n\n## Expected Behavior\nThe 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.\n\n## Actual Behavior\nThe formatter crashes with a `KeyError: None` traceback when attempting to attach step data (tables or text) to the Allure report.\n\n## Steps to Reproduce\n\n### 1. Create a feature file with Rule and data table\n**File: `test/features/simple/tutorial.feature`**\n```gherkin\nFeature: showing off behave\n\n\tRule: Basic arithmetic operations\n\n\t\tScenario: Passing a table as a data through step\n\t\t\tGiven we have behave installed\n\t\t\tWhen we pass a table as a data through step\n\t\t\t\t| number1 | number2 | result |\n\t\t\t\t| 2 | 3 | 5 |\n\t\t\t\t| 4 | 5 | 9 |\n\t\t\tThen behave should be able to read the table\n```\n\n### 2. Create step definitions\n**File: `test/steps/steps_tutorial.py`**\n```python\nfrom behave import given, when, then\n\n@given('we have behave installed')\ndef step_impl(context):\n pass\n\n@when('we pass a table as a data through step')\ndef step_impl(context):\n assert context.table\n\n@then('behave should be able to read the table')\ndef step_impl(context):\n pass\n```\n\n### 3. Run with Allure formatter\n```bash\nbehave -f allure_behave.formatter:AllureFormatter -o allure_result_folder\n```\n\n### 4. Observe the error\n```\nException KeyError: None\nTraceback (most recent call last):\n ...\n File \"allure_behave/listener.py\", line 147, in start_behave_step\n self.logger.attach_data(uuid4(), step_table(step), name='.table', attachment_type=AttachmentType.CSV)\n File \"allure_commons/reporter.py\", line 163, in attach_data\n file_name = self._attach(uuid, name=name, attachment_type=attachment_type,\n File \"allure_commons/reporter.py\", line 153, in _attach\n self._items[last_uuid].attachments.append(attachment)\n File \"allure_commons/reporter.py\", line 33, in __getitem__\n return self.thread_context.__getitem__(item)\nKeyError: None\n```\n\n## Additional Testing\n\n### Works ✅\n- Simple scenarios under `Rule` (no tables/DocStrings)\n- Scenario Outlines with Examples tables under `Rule`\n- All scenario types WITHOUT `Rule` keyword\n\n### Fails ❌\n- Steps with data tables under `Rule`\n- Steps with DocStrings under `Rule`\n\n### Test Results Matrix\n\n| Scenario Type | Without Rule | With Rule |\n|--------------|--------------|-----------|\n| Simple scenario | ✅ Works | ✅ Works |\n| Scenario Outline with Examples | ✅ Works | ✅ Works |\n| Step with data table | ✅ Works | ❌ **Fails** |\n| Step with DocString | ✅ Works | ❌ **Fails** |\n\n## Root Cause Analysis\nThe 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]`.\n\nThe `Rule` hierarchy creates a different context structure that the formatter doesn't handle correctly when attaching step data.\n\n## Suggested Fix\nThe `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.\n\n## Additional Context\n- The `Rule` keyword is a valid Gherkin construct for organizing scenarios\n- Behave 1.2.6+ fully supports the `Rule` keyword\n- This issue prevents using Allure reporting with modern Gherkin best practices\n\n## References\n- Gherkin Rule keyword documentation: https://cucumber.io/docs/gherkin/reference/#rule\n- Behave changelog (Rule support): https://github.com/behave/behave/blob/main/CHANGES.rst\n\n","author":{"url":"https://github.com/hemz10","@type":"Person","name":"hemz10"},"datePublished":"2025-12-01T07:58:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/886/allure-python/issues/886"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:69ed2ca6-9cbb-78de-6b28-d39ad290f141 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A774:B1641:546214:71E27E:696E77C1 |
| html-safe-nonce | 5858d3b5fc045a09e4e25d55b35084883bb7813134fbfc7af7003743bb7e8dfc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzc0OkIxNjQxOjU0NjIxNDo3MUUyN0U6Njk2RTc3QzEiLCJ2aXNpdG9yX2lkIjoiMTA3MzAzMzg4NjMwOTQ0NzYxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e39d7d7aab68a08ddd9a83ed9300d89b25e8b6d6a787ba7ac75165dfa5cf5ec0 |
| hovercard-subject-tag | issue:3679749409 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/allure-framework/allure-python/886/issue_layout |
| twitter:image | https://opengraph.githubassets.com/228ef633781d3187d11ffabc092d665fe0a0e5ddcc0997995cfb1d341e7bb795/allure-framework/allure-python/issues/886 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/228ef633781d3187d11ffabc092d665fe0a0e5ddcc0997995cfb1d341e7bb795/allure-framework/allure-python/issues/886 |
| og:image:alt | 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 versio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hemz10 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 01185010a96388a2a8cd8bd7f5824fdf090522b219f9aecf8c7ff1857aeb489b |
| turbo-cache-control | no-preview |
| go-import | github.com/allure-framework/allure-python git https://github.com/allure-framework/allure-python.git |
| octolytics-dimension-user_id | 5879127 |
| octolytics-dimension-user_login | allure-framework |
| octolytics-dimension-repository_id | 79346720 |
| octolytics-dimension-repository_nwo | allure-framework/allure-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 79346720 |
| octolytics-dimension-repository_network_root_nwo | allure-framework/allure-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 673a80c1bce2a1e6a48b530ce2b72bf8fd253386 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width