Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use of target_fixture not possible anymore #686

Open
chrcoen opened this issue Apr 3, 2024 · 1 comment
Open

Re-use of target_fixture not possible anymore #686

chrcoen opened this issue Apr 3, 2024 · 1 comment

Comments

@chrcoen
Copy link

chrcoen commented Apr 3, 2024

The following test will pass in pytest=8.0.2, pytest-bdd=7.2.1, but will fail in pytest=8.1.0, pytest-bdd=7.2.1.

@given(parsers.parse('the value {value:d}'), target_fixture='x')
def step(value):
    return value

@when(parsers.parse('multiplied by {value:d}'), target_fixture='result')
def step(x, value):
    return x * value

@then(parsers.parse('the result should be {value:d}'))
def step(result, value):
    assert result == value

Scenario: Multiply
    Given the value 7
    When multiplied by 7
    Then the result should be 49
    When multiplied by 3
    Then the result should be 27
result = 49, value = 27

    @then(parsers.parse('the result should be {value:d}'))
    def step(result, value):
>       assert result == value
E       assert 49 == 27

test_multiply.py:26: AssertionError

It seems like the target fixture values are chached and the when step is not executed again.

@alfechner
Copy link

I also setup an example to report the issue and stumbled upon this one.

Feature: Numbers
    Scenario: Increment
        Given the number "1"
        And the number is "1"
        When the number is incremented
        Then the number is "2"
from pytest_bdd import given, parsers, scenario, then, when


@scenario("numbers.feature", "Increment")
def test_increment():
    pass


@given(parsers.parse('the number "{value:d}"'), target_fixture="number")
def the_number(value):
    return value


@when("the number is incremented", target_fixture="number")
def the_number_is_changed_to(number):
    number += 1

    return number


@given(parsers.parse('the number is "{expected_value:d}"'))
@then(parsers.parse('the number is "{expected_value:d}"'))
def the_number_is(expected_value, number):
    assert expected_value == number

While And the number is "1" is fine the Then the number is "2" step feiles since the target fixture number is not correctly updated.

Confirming that pytest == 8.0.2 still works. Thanks @chrcoen for this important detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants