pytest-dev / pytest-bdd

BDD library for the py.test runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.3k stars 219 forks source link

Unexpected behavior in scenario outline #389

Open vytautas-ziurlis-youtility opened 4 years ago

vytautas-ziurlis-youtility commented 4 years ago

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?

WilliamWCYoung commented 3 years ago

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?