:( correct fuel.py passes all test_fuel checks expected exit code 0, not 1
when testing my code, which then prevents the following tests from running
Here is my code for fuel.py:
def main():
fraction = input("Fraction: ")
percent = convert(fraction)
return (gauge(percent))
def convert(fraction):
while True:
try:
numerator = int(fraction.split("/")[0])
denominator = int(fraction.split("/")[1])
percent = float(numerator / denominator)
if percent > 1:
fraction = input("Fraction:")
continue
except (ValueError, ZeroDivisionError):
raise
else:
return percent
def gauge(percent):
if percent >= 0.99:
return "F"
elif percent <= 0.01:
return "E"
else:
return f"{percent *100:.0f}%"
if __name__ == "__main__":
main()
I know this code is 'good' as it passes the original fuel.py tests
My fuel_test.py file looks like this right now:
import pytest
from fuel import convert, gauge
def test_type():
assert type(convert("1/2")) is float
def test_values():
assert gauge(0.01) == "E"
assert gauge(0.99) == "F"
def test_errors():
with pytest.raises(ValueError):
convert('value/error')
with pytest.raises(ZeroDivisionError):
convert('1/0')
It passes when I run pytest in terminal, so Im at a loss for what is happening here. Any help would be appreciated. THX.