Por que o seguinte código pytest-bdd está gerando um erro:
pytest_bdd.exceptions.StepDefinitionNotFoundError: A definição da etapa não foi encontrada: dado "Tenho um carrinho de compras vazio
Aqui está o arquivo de recursos:
Feature: Shopping Cart
As a customer
I want to add products to my shopping cart
So that I can purchase them later
Scenario Outline: Add products to the shopping cart
Given I have an empty shopping cart
When I add <product> to the cart
Then the cart should contain <product> and shelf number is <shelf_num>
Examples:
| product | shelf_num |
| Apples | 5 |
| Bananas | 24 |
| Oranges | 11 |
Aqui estão as etapas:
scenarios('scenario_example_demo.feature')
@pytest.fixture
def shopping_cart():
return []
@given('I have an empty shopping cart')
def empty_shopping_cart(shopping_cart):
assert len(shopping_cart) == 0
@when(parsers.parse('I add {product} to the cart'))
def add_product(shopping_cart, product):
shopping_cart.append(product)
@then(parsers.parse('the cart should contain {product} and shelf number is {shelf_num}'))
def verify_cart_contents(shopping_cart, product,shelf_num):
assert product in shopping_cart and int(shelf_num)>0
Estranhamente, quando altero 'Given' para 'When' no arquivo de recurso e faço o mesmo no código de etapas, o código funciona.
créditos do código: do Médio (Ramkumar R)