Voltar à lição

examples/test_item_price.py

O código e as telas originais dos produtos mantêm o idioma original. A lição os explica no idioma selecionado.

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)