My apologies if this is not the proper outlet for this type of technical issue. It wasn’t clear if this should be done on Github or via the forum.
I’ve been trying to figure out the cause of this error I’m getting while running a test for a single function (exchange_money()
). I’m struggling to track this down due to my unfamiliarity with python. I’ve tested my changes using a python REPL, and the result is exactly what I’d expect, but the test for this function fails.
Here’s my code:
def exchange_money(budget, exchange_rate):
"""
:param budget: float - amount of money you are planning to exchange.
:param exchange_rate: float - unit value of the foreign currency.
:return: float - exchanged value of the foreign currency you can receive.
"""
budget / exchange_rate
And the Test function:
@pytest.mark.task(taskno=1)
def test_exchange_money(self):
input_data = [(100000, 0.8), (700000, 10.0)]
output_data = [125000, 70000]
for variant, (input_data, output_data) in enumerate(zip(input_data, output_data), start=1):
with self.subTest(f"variation #{variant}", input_data=input_data, output_data=output_data):
self.assertAlmostEqual(exchange_money(input_data[0], input_data[1]), output_data)
This is the output from running this test:
============================= test session starts ==============================
collecting ... collected 1 item
exchange_test.py::CurrencyExchangeTest::test_exchange_money
======================== 1 failed, 6 warnings in 0.03s =========================
FAILED [100%]
exchange_test.py:13 (CurrencyExchangeTest.test_exchange_money)
self = <exchange_test.CurrencyExchangeTest testMethod=test_exchange_money>
@pytest.mark.task(taskno=1)
def test_exchange_money(self):
input_data = [(100000, 0.8), (700000, 10.0)]
output_data = [125000, 70000]
for variant, (input_data, output_data) in enumerate(zip(input_data, output_data), start=1):
with self.subTest(f"variation #{variant}", input_data=input_data, output_data=output_data):
> self.assertAlmostEqual(exchange_money(input_data[0], input_data[1]), output_data)
E TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
exchange_test.py:21: TypeError
Process finished with exit code 1
Is my solution actually incorrect? What should I do to ensure this test passes?