pytest-dev / pytest-dev/pytest-bdd
Failed to combine pytest parametrization, scenario outline and example table
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 251
- Avg merge
- 43m
- Merged PRs (30d)
- 2
Description
I tried to combine pytest parametrization, scenario outline and example table but it failed due to ScenarioExamplesNotValidError:
Scenario "Outlined given, when, thens" in the feature "/home/smacs/workspace/next-battery/src/main/python/parametrized_with_examples.feature" has not valid examples. Set of step parameters [u'eat', u'fruits', u'left', u'start'] should match set of example values ['fruits']
It looks like pytest parametrization parameters are not added to parameters from example table
File: parametrized_with_examples.feature
Feature: Outline
Scenario Outline: Outlined given, when, thens
Given there are <start> <fruits>
When I eat <eat> <fruits>
Then I should have <left> <fruits>
Examples:
| fruits |
| pears |
| pumpkins |
File: test_parametrized_with_examples.py
import pytest
from pytest_bdd import given, when, then, scenario
@given('there are <start> <fruits>')
def start_fruits(start, fruits):
assert isinstance(start, int)
return {fruits: dict(start=start)}
@when('I eat <eat> <fruits>')
def eat_fruits(start_fruits, eat, fruits):
assert isinstance(eat, float)
start_fruits[fruits]['eat'] = eat
@then('I should have <left> <fruits>')
def should_have_left_fruits(start_fruits, start, eat, left, fruits):
assert isinstance(left, str)
assert start - eat == int(left)
assert start_fruits[fruits]['start'] == start
assert start_fruits[fruits]['eat'] == eat
@pytest.mark.parametrize(
['start', 'eat', 'left'],
[(12, 5, 7)])
@scenario(
'parametrized_with_examples.feature',
'Outlined given, when, thens',
example_converters=dict(start=int, eat=float, left=str)
)
def test_outlined_feature(start, eat, left):
pass
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with test_parametrized_with_examples.py and parametrized_with_examples.feature, then run the shown pytest test to reproduce ScenarioExamplesNotValidError. Trace how @pytest.mark.parametrize and @scenario process the outline and example table. Done means the combined parametrization runs successfully and the existing assertions pass for the example rows.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100