| 1 |
# mypy: allow-untyped-defs |
| 2 |
from __future__ import annotations |
| 3 |
|
| 4 |
from pytest_bdd import given |
| 5 |
from pytest_bdd import scenario |
| 6 |
from pytest_bdd import then |
| 7 |
from pytest_bdd import when |
| 8 |
|
| 9 |
import pytest |
| 10 |
|
| 11 |
|
| 12 |
@scenario("bdd_wallet.feature", "Buy fruits") |
| 13 |
def test_publish(): |
| 14 |
pass |
| 15 |
|
| 16 |
|
| 17 |
@pytest.fixture |
| 18 |
def wallet(): |
| 19 |
class Wallet: |
| 20 |
amount = 0 |
| 21 |
|
| 22 |
return Wallet() |
| 23 |
|
| 24 |
|
| 25 |
@given("A wallet with 50") |
| 26 |
def fill_wallet(wallet): |
| 27 |
wallet.amount = 50 |
| 28 |
|
| 29 |
|
| 30 |
@when("I buy some apples for 1") |
| 31 |
def buy_apples(wallet): |
| 32 |
wallet.amount -= 1 |
| 33 |
|
| 34 |
|
| 35 |
@when("I buy some bananas for 2") |
| 36 |
def buy_bananas(wallet): |
| 37 |
wallet.amount -= 2 |
| 38 |
|
| 39 |
|
| 40 |
@then("I have 47 left") |
| 41 |
def check(wallet): |
| 42 |
assert wallet.amount == 47 |