Skip to content

pytest-bdd callbacks not called #174

@PiotrNestor

Description

@PiotrNestor

How to get the pytest-bdd callbacks
I tried the following implementation(,but the callback is NOT called):

import pytest

@pytest.mark.tryfirst
def pytest_bdd_after_scenario(request, feature, scenario):
    print("After scenario")

The complete example:
Execute with: PYTHONPATH=. python outline.py

outline.feature

Feature: Example

Scenario Outline: Outlined given, when, then
Given there are <start> cucumbers
When I eat <eat> cucumbers
Then I should have <left> cucumbers

Examples:
| start | eat | left |
|  12   |  5  |  7   |
|  12   |  6  |  6   |

outline.py

import pytest
from pytest_bdd import given, when, then, scenario
from steps import *

@scenario(
    'outline.feature',
    'Outlined given, when, then',
    example_converters=dict(start=int, eat=float, left=str)
)
def test_outlined():
    pass

if __name__ == '__main__':
    pytest.main(args=['-q', '-s', __file__])

steps.py

import pytest
from pytest_bdd import given, when, then, scenario

@pytest.mark.tryfirst
def pytest_bdd_after_scenario(request, feature, scenario):
    print("After scenario")


@given('there are <start> cucumbers')
def start_cucumbers(start):
    print("\nStart")
    assert isinstance(start, int)
    return dict(start=start)


@when('I eat <eat> cucumbers')
def eat_cucumbers(start_cucumbers, eat):
    print("Eat")
    assert isinstance(eat, float)
    start_cucumbers['eat'] = eat


@then('I should have <left> cucumbers')
def should_have_left_cucumbers(start_cucumbers, start, eat, left):
    print("Validate result")
    assert isinstance(left, str)
    assert start - eat == int(left)
    assert start_cucumbers['start'] == start
    assert start_cucumbers['eat'] == eat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions