Back to lesson

examples/test_item_price.py

Code and original product screens keep their original language. The lesson explains them in your selected language.

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)