Why does whichever function on the bottom return an assertion error in pytest parametrize

  parametrize, pytest, python

I’m trying to make a vending machine using python. money_box accepts currencies that are allowed in the machine and change accepts money that aren’t allowed in the machine. Whenever I run a pytest on the file, whichever function that is in the bottom gets an assertion error (either def test_money_box() or def test_change(). Is this a simple mistake or am I misunderstanding how to use parametrize? Thank you

from vending_machine.money import Money
from vending_machine.vending_machine import VendingMachine
import pytest


@pytest.mark.parametrize(
    "money, change",
    [
        (Money.M_1, [Money.M_1]),
        (Money.M_5, [Money.M_1, Money.M_5]),
        (Money.M_10, [Money.M_1, Money.M_5]),
        (Money.M_50, [Money.M_1, Money.M_5]),
        (Money.M_100, [Money.M_1, Money.M_5]),
        (Money.M_500, [Money.M_1, Money.M_5]),
        (Money.M_1000, [Money.M_1, Money.M_5]),
        (Money.M_2000, [Money.M_1, Money.M_5, Money.M_2000]),
        (Money.M_10000, [Money.M_1, Money.M_5, Money.M_2000, Money.M_10000]),
    ],
)
def test_change(cash, change):
    VendingMachine.insert(cash)
    assert VendingMachine.change == change


@pytest.mark.parametrize(
    "cash, money_box",
    [
        (Money.M_1, []),
        (Money.M_5, []),
        (Money.M_10, [Money.M_10]),
        (Money.M_50, [Money.M_10, Money.M_50]),
        (Money.M_100, [Money.M_10, Money.M_50, Money.M_100]),
        (Money.M_500, [Money.M_10, Money.M_50, Money.M_100, Money.M_500]),
        (
            Money.M_1000,
            [Money.M_10, Money.M_50, Money.M_100, Money.M_500, Money.M_1000],
        ),
        (
            Money.M_2000,
            [Money.M_10, Money.M_50, Money.M_100, Money.M_500, Money.M_1000],
        ),
        (
            Money.M_10000,
            [Money.M_10, Money.M_50, Money.M_100, Money.M_500, Money.M_1000],
        ),
    ],
)
def test_money_box(cash, money_box):
    VendingMachine.insert(cash)

    assert VendingMachine.money_box == money_box

Source: Python Questions

LEAVE A COMMENT