examples/test_item_price.py
تحتفظ الشفرة وشاشات المنتجات الأصلية بلغتها الأصلية. يشرحها الدرس بلغتك المختارة.
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)