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

Unexpected behavior in scenario outline

Open vytautas-ziurlis-youtility opened this issue 5 years ago • 1 comments
trafficstars

Hi,

I have noticed unexpected behavior when using scenario outline. Here's a simple example to demonstrate it:

File test.scenario:

Feature: Test feature

  Scenario Outline: Scenario 1
    When Action "A" is taken
    And Some other action "<action>" is taken

    Examples: Actions
      | action |
      | B      |

File steps.py:

import pytest
from pytest_bdd import scenarios, given, when, then, parsers

scenarios('test.feature', example_converters={ 'action': str })

@when(parsers.parse('Action "{action}" is taken'))
def take_action1(action):
    print('take_action1:%s'%action)
    pass

@when('Some other action "<action>" is taken')
def take_action2(action):
    print('take_action2:%s'%action)
    pass

In this particular case I would expect to see the following in the output:

take_action1:A
take_action2:B

However, what I see is this:

take_action1:A
take_action2:A

Strangly this problem goes away if I rename action argument for one of the steps, for example:

@when(parsers.parse('Action "{action}" is taken'))
def take_action1(action):
    print('take_action1:%s'%action)
    pass

@when('Some other action "<action2>" is taken')
def take_action2(action2):
    print('take_action2:%s'%action2)
    pass

I have a feeling that arguments are somehow "cached" or memoized by name and was wondering is this expected behavior?

I second this finding, I was trying to debug this for ages and changing the name to something unique fixed it. It would be great to be able to reuse the names as they're not actually used within the same context?

WilliamWCYoung avatar Sep 07 '21 09:09 WilliamWCYoung