examples/test_item_price.py
Le code et les écrans originaux des produits gardent leur langue d’origine. La leçon les explique dans la langue choisie.
import pytest
def calculate_item_price(item):
if item["type"] == "book":
return item["price"] * 0.90
return item["price"]
def test_book_gets_ten_percent_discount():
assert calculate_item_price({"type": "book", "price": 100}) == pytest.approx(90)
def test_other_item_keeps_its_price():
assert calculate_item_price({"type": "other", "price": 100}) == pytest.approx(100)