pytest-bdd icon indicating copy to clipboard operation
pytest-bdd copied to clipboard

Failed to combine pytest parametrization, scenario outline and example table

Open kaniapm opened this issue 8 years ago • 7 comments
trafficstars

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

kaniapm avatar May 17 '17 10:05 kaniapm