feat: add examples tag to scenario tags#771
Conversation
|
Thanks for the PR! Could you add tests for this? |
|
@jsa34 I've added some tests but I have issue with the test test_step_outside_scenario_or_background_error that is no longer working with a strange behavior of pytest inception... |
|
@jsa34 I have the feeling that a step outside a scenario no longer raised an error in get_gherkin_document |
|
@jsa34 I finally had time to debug a bit and the issue is that the step outside the scenario is interpreted as a comment |
|
@jsa34 I'm removing the failing test as in my point of view the behavior that was tested is no longer relevant. |
gherkin-official >=29 parses a Given/When/Then line that appears before the first Scenario or Background as part of the feature description rather than raising a parse error. The old test_step_outside_scenario_or_background_error asserted a FeatureError that no supported gherkin version (29..37, latest) emits anymore, so it failed across the entire tox matrix. Replace it with a parser-level test that pins the actual current behavior: the orphan step lands in feature.description and the scenario still parses. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
find_scenario_example_from_context only compared the first row of each Examples block, so any parametrization context coming from a later row failed to match and lost its block's tags. Reuse Examples.as_contexts() - the same generator that produces the rendering context - so matching covers every row of every block. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The suite does not pass on two dependency versions, independently of this PR (the same jobs are red on the latest main CI run): - pytest 7.x: ~12 tests in tests/feature and tests/args fail because the current code relies on pytest 8 step-error reporting semantics. - gherkin-official 31.0.0: an anomalous release; tests pass on 29, 30 and 32..latest but test_outline_with_escaped_pipes, test_scenario_comments and test_parser fail only on 31. Restrict the matrix to the versions the suite actually supports. Verified the full py3.12 matrix (pytest 8.0..latest x gherkin 29,30,32..latest) passes locally. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
@jsa34 @youtux — reviving this one, sorry for the long gap. I've rebased onto current main and cleaned everything up. Summary of where it stands: What this PR does Propagates tags declared on an Examples: block onto the scenarios generated from that block. Gherkin already parses Examples-level tags, but they were dropped during rendering — so you Scenario Outline: ... @smoke now ends up on the generated scenario's tags. On the test you asked about Back in April I'd removed test_step_outside_scenario_or_background_error because it failed and I couldn't explain it. I've now traced it properly: since gherkin-official >=29, a step before About CI While getting this green I found main's own CI is red independently of this PR — the same five jobs fail on the latest main run. Two pre-existing causes in the tox matrix:
I've restricted the matrix to the versions the suite actually supports (pytest>=8.0, gherkin 29,30,32..latest); the full matrix is green now on my fork. Happy to pull that matrix change Could you approve the workflow run on this PR and take another look when you have a moment? Glad to adjust anything. |

Summary
Scenario Outlines can carry tags on individual
Examples:blocks, but thosetags were lost when each example row was rendered into a concrete scenario.
Gherkin parses them; pytest-bdd just never propagated them. This PR carries an
Examples:block's tags onto every scenario generated from that block, so theybehave like any other scenario tag (selection,
pytest_bdd_apply_tag, marks).Motivation
Given a tagged examples table:
Before this PR, neither @smoke nor @Edge-Case reached the generated
scenarios. After it, each generated scenario inherits the tags of the
Examples: block it came from (in addition to the scenario- and feature-level
tags). This makes it possible to filter or mark specific example sets.
What changed
into the rendered Scenario.tags.
every Examples block (via Examples.as_contexts() — the same generator
that produces the context), so it works for multi-row blocks and multiple
blocks, not just the first row.
Tests
scenario.
regardless of which row the context comes from.
test_step_before_first_scenario_is_parsed_as_description: with
gherkin-official >=29, a step before the first Scenario/Background is no
longer an error — it is parsed as the feature description. The old test
asserted a FeatureError that no supported gherkin version raises. See the
discussion below.
Notes
incompatible with the current code, and gherkin-official 31.0.0 is an
anomalous release where three unrelated tests fail). I restricted the tox
matrix to the supported versions so this PR is green; happy to split that
into its own PR — details in the comment thread.